My class has a std::vector member that works fine when declared like this -
Code:
private:
std::vector<Position> path;
But I want to be able to give it an initial size (of say 20) like
Code:
private:
std::vector<Position> path(20, 0);
But g++ complains when I do this, which I kinda expected it would. Is there a way to get around this? I tried to make a local vector in my constructor with that size and then set it equal to it like -
Code:
Path::Path() {std::vector<Position> temp(20); path = temp;}
But when I tried to access path.at(19) to test it, I got a segmentation fault. Can someone explain why this way won't work and/or a way to accomplish this? Any help is appreciated.