-
Vector question
Hello, I have created a vector of pointers.
If I resize my vector, will it be filled in with NULL values?
Or will it point to garbage? If it will point to garbage, how do I init them on NULL?
Code:
vector< vector< Tile*> > board;
board.resize(size);
for (int i = 0; i < size; i++)
board[i].resize(size);
This does not work because I am pointing to the values:
Code:
for(int i =0; i < size; i++)
{
for(int j=0; j < size; j++)
{
board[i][j] = NULL;
}
}
Thank you
-
push_back
You could try using the push_back() method, and I know that int vectors are set to default value of 0, so maybe?
-
You should be supplying the other argument to resize()
board[i].resize(size, NULL);
-
I believe that if you resize a vector, all of the values will be default-constructed, so that would mean NULL, yes.
However, whiteflags has a point. You shouldn't be using resize anyway, unless you have a very specific requirement. Use push_back, and if possible, don't use pointers.