Reputation: 313
I'm trying to create a vector of objects, i don't know what is going wrong.
here the code
class nave {
public:
void sx(int i); int x();
void sy(int i); int y();
};
vector<nave> naves();
naves.push_back(nave);
cout << naves.size();
Upvotes: 0
Views: 916
Reputation: 52157
Do this:
vector<nave> naves;
naves.push_back(nave());
vector<nave> naves();
was interpreted as a function declaration.naves.push_back(nave);
did not actually instantiate nave
.Upvotes: 2
Reputation: 16709
A vector is just like any other class. Declare it thus:
vector<nave> naves;
Upvotes: 4
Reputation: 34665
Change -
vector<nave> naves(); // naves() is a function declaration whose return type
// is vector<nave>
to
vector<nave> naves;
Upvotes: 4