• Advertisement
Sign in to follow this  

Multidimensional containers

This topic is 4949 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible to have multi-dimentional containors that are part of the STL. I was hoping I would be able to have an 'unlimited' isometric map with layers. so would vector <whatever> name[2][2] create a 3D array? Is there a way to do this?

Share this post


Link to post
Share on other sites
Advertisement
I am not familiar with STL so I can't say for sure, but you should be able to make a vector <vector< whatever >>

Share this post


Link to post
Share on other sites
+1 to GreenToad.

Note that it is necessary to have a space between the closing angle brackets - otherwise the lexer sees a shift operator, and the rest of the compiler gets very confused.

Share this post


Link to post
Share on other sites
well, i think he wants to have many layers in his map an "infinite" (IE expandable) layered map.

for this you would need the extremely ugly but flexible vector of vectors of vectors.

vector< vector < vector<Tile> > > map;

then you could do

map[layer][x][y]

if you want to add a new layer, just do

map.push_back(vector< vector <Tile> >);

initialization would be something like


for(int l = 0; l < blah; l++)
{
for(int x = 0; x < width; x++)
{
for(int y = 0; y < height; y++)
{
map[l][x][y].stuff = blah;
}
}
}


id recommend using a typedef =)

Share this post


Link to post
Share on other sites
Quote:
id recommend using a typedef =)

You just saved me a ton of typing!

Quote:
vector< vector< whatever > > names;

Thanks!

I never knew how to do this, rate-ups for all!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement