Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Christiaan

Dynamic multi-dimension arrays

This topic is 6921 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

I''m trying to make an dynamic map for an isometric game, using linked list for the layers. using C++ so I prefer using the new/delete operator over malloc. I have an structure for every cell ''STile'' and a class ''CMap'' for the map and using the function Createmap() to create the map and set all the map[row][column].next to NULL. the problem is that the statement in the 2 for loops doing this doesn''t seem to work none of the values is set to NULL, but if I add map[32][32].next or what ever legal array coordinate that one is set to NULL, so why does that work and does the statement using for loops not work, what am I doing wrong??? can someone plz help me... here''s the code that''s keeping me busy... typedef struct STile NODE; typedef NODE *NODE_PTR; struct STile { STile *next; char type; char flags; }; class CMap { public : STile **map; int width; int height; CreateMap(); }; CMap::CreateMap() { int i, row, column; *map = new STile [width]; for (i=0; i = new STile [height]; } for (row = 0; row < height; row++) { for (column = 0; column < width; column++) { map[column][row].next = NULL; } } }

Share this post


Link to post
Share on other sites
Advertisement
What you want is something like (not in your object framework in one block to make things clear):

typedef STile * pSTile;
STile ** map = new pSTile[width];
for (int i = 0; i < width; i++) {
map[ i ] = new Stile[height];
for (int j = 0; j < height; j++) {
map[ i ][ j ].next = NULL;
}
}

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!