【发布时间】:2015-12-07 10:25:13
【问题描述】:
以下代码 sn-p 来自 Herb Sutter 的博客here
g++ 输出10。 MSVC 也输出10。不同编译器的输出可能不同。
我不明白变量i 是如何递增的。
谁能解释一下为什么输出是10,10 的输出真的正确吗?
#include <iostream>
#include <vector>
#include <string>
int main()
{
std::vector<int> v = { 0, 0 };
int i = 0;
v[i++] = i++;
std::cout << v[0] << v[1] << std::endl;
}
【问题讨论】:
标签: c++11 vector order-of-execution