I’m having a problem resizing my two dimensional vectors.
std::vector<std::vector<NavigationNode>> *nodes;
nodes->resize(sizex);
for(unsigned int i=0; i<sizex ;i++)
nodes[i].resize(sizey);
It works as intended when i is 0, but crashes when i is 1.
Do you know why?
You’ve defined the type of
nodesto be a pointer to a vector of vectors. Presuming that this pointer has been initialized to correctly allocated memory,nodes[i]is not calling operator[] on the outer vector, it’s accessing the memorynodespoints to as if it is a contiguous array. It is equivalent to*(nodes+i).In this case, more correct syntax would be
(*nodes)[i].