Struggling with 2D std::vector in c++
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.
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
Popular Topics
Advertisement