Dynamic multi-dimension arrays
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;
}
}
}
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 = new Stile[height];<br> for (int j = 0; j < height; j++) {<br> map[ j ].next = NULL;<br> }<br>}<br> </pre>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement