arrays - C++ 2d Vector subscript out of range error -
currently in function, have method declares 2d vector.
vector <vector<test> > path(int x, int y) //path function { vector <vector<test>> mazearray(column, vector<test>(row)); //declaring object (int = 0; < column; a++) { (int b = 0; b < row; b++) { mazearray[b][a].setx(b); mazearray[b][a].sety(a); } } }
for example, when tried run function, path(10,10).
the double loop works without error, if change path example, path(11,10) or path (11,13) or numbers not same both (int x , y), error vector subscript out of range present.
why so? can me on this? there way fix such value type acceptable? thanks.
the loop in function
vector <vector<test> > path(int x, int y) //path function { vector <vector<test>> mazearray(column, vector<test>(row)); //declaring object (int = 0; < column; a++) { (int b = 0; b < row; b++) { mazearray[b][a].setx(b); mazearray[b][a].sety(a); } } }
is wrong. have exchange b , in indices. there should be
(int = 0; < column; a++) { (int b = 0; b < row; b++) { mazearray[a][b].setx(b); mazearray[a][b].sety(a); } } }
take account meaning of function parameters unclear because not used.:)
Comments
Post a Comment