Quote:But if I understand my code correctly, blocked_space.all_blocked_space[solid_group] should refer to a vector and should be able to be sized.
No, it is referering to a BlockedSolidGroup which does contain a vector<BlockedSolid>. You will have to use blocked_space.all_blocked_space[solid_group].blocked_solids to get to the vector.
Quote:Someone told me that 2D vectors were not possible in C++.
You can make a vector of vectors like this: vector<vector<BlockedSolid> >. Note the space between the two > >. It is necessary to prevent the compiler from parsing it as a single >> operator (that's one of C++'s flaws). It will not really be a 'true' 2D vector, since each individual vector can be resized independently.
You could, however, write your own 2D vector class (or use an existing one, like
boost::multi_array or
blitz::Array).
A
minimalistic 2D vector class could look like:
template<class T>class vector2d{ size_t m_rows, m_cols; std::vector<T> m_data;public: vector2d() {} vector2d(size_t rows, size_t cols) : m_rows(rows), m_cols(cols), m_data(rows*cols) {} T& operator()(size_t row, size_t col) { return m_data[row*m_cols+col]; } const T& operator()(size_t row, size_t col) const { return data[row*m_cols+col]; } void resize(size_t rows, size_t cols) { m_data.resize(rows*cols); m_rows = rows; m_cols = cols; }};
Of course, such an implementation is
far from being a real STL container. Also, it is indexed as vec(x,y) and not vec[x][y], though the later syntax could be possible in a more complex class (returning a proxy row object when you use []).
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan