Teofrostus
Teofrostus

Reputation: 1606

Cannot make a vector of structs in C++

I'm trying to do the following:

struct Code
{
    GF2X generator;
    vector<GF2X> codeWords;
};

vector<Code> allCodes;

However, I end up with this error:

error: template argument for 'template<class _Alloc> class std::allocator' uses local type 'main()::Code'|

I'm completely lost as to what this means. This is also my first time programming in C++.

Upvotes: 1

Views: 242

Answers (3)

In C++03 local classes (classes defined inside a function) cannot be used as template arguments. That restriction was lifted in C++11, but if your compiler does not have support for this feature you can always move the type definition outside of the function at namespace level.

Upvotes: 5

jahhaj
jahhaj

Reputation: 3119

You haven't posted all your code, but I'm guessing that you put struct Code ... inside your main function. Try moving it above the start of main.

Upvotes: 0

Griwes
Griwes

Reputation: 9029

Define the struct outside (but before) your int main().

Upvotes: 3

Related Questions