Reputation: 3101
Why does this
#include <vector>
void f()
{
struct S
{
int first, second, third;
};
std::vector<S> vs;
}
work with Visual C++ 2015, but not with g++ 4.8.4?
Upvotes: 2
Views: 79
Reputation: 41210
Ensure you are compiling with at least -std=c++0x
.
In C++11, the standard was modified to allow for local classes to be template arguments (for lambda support). If you target pre-C++11, this won't work.
If you're compiling MSVC, it will enable C++11 by default, which is not so with clang and pre-gcc 6
See also: What restrictions does ISO C++03 place on structs defined at function scope?
Demo (GCC 4.8.4) w/ C++11 (Works)
Demo (GCC 4.8.4) without C++11 (Doesn't work)
Upvotes: 8