Struggling with 2D std::vector in c++

Started by
10 comments, last by me22 14 years, 4 months ago
It is probably because your getBoardSize member function is still doing what Zipster told you was causing problems. You almost never need to know the board size you really need to know the height and width of the board and operate on that information. It just so happens the height and width are the same and are equal to the square root of boardSize.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Advertisement
A nice trick to initialize a "2D" vector:
vector<vector<int> > v(height, vector<int>(width, default_value));

This topic is closed to new replies.

Advertisement