为什么会这样
#include <vector>
void f()
{
struct S
{
int first, second, third;
};
std::vector<S> vs;
}
使用Visual C ++ 2015,但不能使用g ++ 4.8.4?
答案 0 :(得分:8)
确保您至少使用-std=c++0x
进行编译。
在C ++ 11中,修改了标准以允许本地类成为模板参数(对于lambda支持)。如果你的目标是预C ++ 11,那就不行了。
如果您正在编译MSVC,默认情况下它将启用C ++ 11,而clang和pre-gcc 6则不然。
另请参阅:What restrictions does ISO C++03 place on structs defined at function scope?