Skip to main content
gamedev.net
🔒 Locked

Why doesn't this work?

Started by SteveBrown Aug 25, 2000 at 4:29 PM 5 replies 750+ views
Original Post
SteveBrown
SteveBrown
I get 6 errors from each of the last three lines of the follwoing code section. Why doesn''t this work? Thanks in advance for any help!
    
ifstream IMap;
IMap.open ("World\\Maps\\Map1.dat");

int MapX;
int MapY;

IMap>>MapX>>MapY;

D3DVERTEX *TileData[5][MapX][MapY];
D3DMATRIX *TileMatrix[5][MapX][MapY];
int Tile[5][MapX][MapY];
    
Snyper
Snyper
I dont think you can initialize variables like that. Try initializing them at the top with fixed values. Like:
D3DVERTEX *TileData[5][MAX_MAP_X][MAX_MAP_Y];
D3DMATRIX *TileMatrix[5][MAX_MAP_X][MAX_MAP_Y];
int Tile[5][MAX_MAP_X][MAX_MAP_Y];

And make the MAX_MAP_X & MAX_MAP_Y defines as some large value.

Snyper
=============================Where's the 'any' key?=============================
SteveBrown
SteveBrown
Thanks for replying!

MapX and MapY are the sizes of the maps, so that is not the problem, and also, I am using new to create the first two things in the list (these are arrays of pointers, so I am using new to make the objects they point to). The third one I could probably use new for since it is an actual object.

Any other ideas why this doesn''t work?
SteveBrown
SteveBrown
Oh! That makes sense! Thanks a lot! I understand why it doesn''t work now.

Thanks!
SteveBrown
SteveBrown
I was thinking about this after and I am not sure now that even this will work.

What I need is a 3 dimensional array of pointers that has it''s size determined at run-time. Each pointer in this array needs to point to an array of objects.

Would this work like this:

    
D3DVERTEX *PointerArray;

PointerArray = new *D3DVERTEX[x][y][z];
...
...
PointerArray[x][y][z] = new D3DVERTEX[3];


Does this work? Or is there a better way to do this? Thanks again.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.