I have a simple custom class, Foo , and I want to make a vector of Foo objects. In my .h file I declare the vector like this:
std::vector<Foo> bar;
I then try and initialize it to have a capacity in the .cpp file like this:
vector<Foo> bar;
bar.resize(10);
Foo has a custom constructor:
Foo(string name, int number)
Which gives me a compile error:
a.cpp:20:6: error: request for member 'resize' in 'bar',
which is of non-class type 'std::vector<Foo>()'
How can I initialize the vector of custom objects?
The compiler thinks
baris a function (that takes no parameters and returnsvector<Foo>), not a variable of typevector<Foo>. So you have put some wrong brackets somewhere.