Archived

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

Gilzu

how to use dynamic arrays?

Recommended Posts

Gilzu    122
lets say i wanna do a matrix: WORD Map[x][y] how can i allocate this dynamic array with still refering to it as a matrix? 10x, Gil

Share this post


Link to post
Share on other sites
Oluseyi    2103
WORD **Map;
Map = new (char *)[x];
for(int j = 0; j < x; ++j)
Map[j] = new char[y];

You can now access any element Map[j][k] (j < x and k < y).

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Drop the parentheses. I find that behavior very odd, though...

Map = new char *[x];

Share this post


Link to post
Share on other sites