在基于范围的for循环中声明循环变量与我在循环的表达式语句中使用的名称相同是否合法?我希望这个例子能清楚地说明这一点。
#include <iostream>
#include <vector>
struct bar {
std::vector<int> nums;
};
int main()
{
bar b;
b.nums = {1, 2, 3};
for(int b : b.nums)
std::cout << b << std::endl;
}
gcc 4.8给出了一个错误,而clang 3.2允许它。
https://stackoverflow.com/questions/16407212
复制相似问题