I have written my first program using vector, however I can't get it to compile. Lines using vector, like: std::vector<sf::Image> iPlants(60);
return the errors:
error: expected identifier before numeric constant|
error: expected ',' or '...' before numeric constant|
Also, I also had problems with this line: std::vector<int> Evolution::ReturnX()
I got a 'invalid declarator before 'Evolution''.
That was an oversight of mine. But if I can create a vector in a class why this simple code won't run?
1 2 3 4 5 6 7 8 9
#include <cstdlib>
#include <vector>
class Something
{
std::vector<int> x (40);
};
int main()
{
}
If I put it inside a function or something I get no error... But I guess that once the program leaves the method's context that vector will be lost, right?
You can only initialize static const integral members within a class. For objects, you can only declare them. For your vector, you would have to declare it as a member without explicitly using a constructor (thus, using the default constructor).
This will do what you intend in the above example: