c++ - How can I resize a 2D vector of objects given the width and height? -
my class, gameboard
, has member variable 2d vector of object of class tile
. gameboard
constructor takes width , height parameters.
how can 2d vector of tile
objects resize according width , height passed constructor? how can fill tile
objects can this?
myvector[i][j].getdisplaychar();
snippet
m_vvtiles.resize(iheight); for(auto = m_vvtiles.begin(); != m_vvtiles.end(); it++ ){ (*it).resize(iwidth,tile(' ')); }
you have resize outer , inner vectors separately.
myvector.resize(n); (int = 0; < n; ++i) myvector[i].resize(m);
Comments
Post a Comment