Bonita Montero
Bonita Montero

Reputation: 3101

std::vector<T> with function-local type

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

Answers (1)

AndyG
AndyG

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?

Upvotes: 8

Related Questions