Skip to main content
gamedev.net
🔒 Locked

creating multidimensional array

Started by HardMario Apr 27, 2003 at 3:17 PM 3 replies 350+ views
Original Post
HardMario
HardMario
I''m trying to make a multidimensional array on the fly, but the compiler doesn''t like what i''m doing. Here is what I''m tyring to do: CLinkedList* GridArray; ... int X = Width/LargestWidth; int Y = Height/LargestHeight; GridArray = new CLinkedList[X][Y]; In that last line, I can assign the GridArray to a single dimensional array no problem, since an array is merely a pointer after all. But if I try to do it with a multidimensional array like I need to, the compiler barks and it''s a no go. Is my syntax wrong, or am I trying to do something that is impossible pointer wise?
Nathaniel Hammen
Nathaniel Hammen
You left out part of it:

int X = Width/LargestWidth;
int Y = Height/LargestHeight;
CBlah** = new CBlah* [X];
for (int K = 0; K < X; K++)
{
CBlah[K] = new CBlah[Y];
}

You have to do an array for BOTH dimensions.

--------------------------------------
I am the master of stories.....
If only I could just write them down...
I am the master of ideas.....If nly I could write them down... o
Zipster
Zipster
Or you allocate one big array and use some modified logic to find the linear index from a row/column pair.
HardMario
HardMario
Oh yeah, I can''t believe I forgot to do that. My C++ is def a little rusty. Thanks for the help fellas.

Topic Locked

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

Sign in to reply to this topic.