Anyway, when I try to complie this, I get an error on my last listed line saying that 'size' is not a member of 'BlockedSolidGroup.' 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.
So obviously I am missing something here.
Someone told me that 2D vectors were not possible in C++. (I am using Visual C++ 6.0) He said that a corect implementation would involve pointers and would be defined something like this:

int *a, *b;
a = b;

Unfortunatly, my understanding on pointers is very shaky at best (I am trying to fix this). I know that a pointer is a data type that holds a memory location. But I am not sure how that is different from any variable, which presumably has a certain place in memory. Nor am I sure how pointers can be used to solve my original problem of a nD resizable array.
Thanks for any assiatance.
Curtis

To dnamically resize, you need to have something to resize it, which I usually use a temporary vector.~~~To answer your question...Not sure why that isn't working...Did you #include <vector> & using namespace std;? That's my random and probably pointless guess.

Share this post

Link to post

Share on other sites

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.

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 []).