Public Group

# Multidimensional containers

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

## 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 on other sites
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 on other sites
This is how you do what you are trying to do:

vector< vector< whatever > > names;

##### Share on other sites

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 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 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 on other sites
It's possibly better to use the boost.multi_array library.

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 11
• 27
• 12
• 12
• 11
• ### Forum Statistics

• Total Topics
631407
• Total Posts
2999914
×