This is for a project I am doing for my college class and I could not find an answer for this that worked for me anywhere. Its very likely I did not understand the answers thou
For class members, you do not initialise them where you declare them (as the list of members is just that: a list of types and names), but instead in the constructor's member initialisation list.
Like this:
class Menu
{
std::vector<menuItem> mi; // no initialiser here
Menu() : mi(20) {}; // but in the ctor-initializer instead
};
You're trying to pass parameters to a constructor of a non-static class member as part of the declaration, which is wrong.
Basically, you'll have to declare the data member in the declaration like this:
std::vector<menuitem> mi;
and as part of the constructor, call the appropriate resize, if that is even necessary.
Unless you know you need a minimum vector size of 20, I would forget about pre-sizing it and just let it grow as necessary.
You can do this in C++11 like so
class Menu
{
private:
std::vector<menuItem> mi = std::vector<menuItem>(20);
};
or if you are stuck using C++03 you will need to initialize it in the constructors initializer list
class Menu
{
public:
Menu() : mi(20) {}
private:
std::vector<menuItem> mi;
};