how to use dynamic arrays?

Started by
3 comments, last by Gilzu 22 years, 5 months ago
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
[email=gil@gilzu.com]Gil Zussman[/email]Check out Goose Chase, Coming this fall!http://www.gilzu.com
Advertisement
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).
doesnt work
see, he doesnt accept the [] in
Map = new (char *)[x];


Gil

Edited by - GilZu on November 3, 2001 3:35:47 PM
[email=gil@gilzu.com]Gil Zussman[/email]Check out Goose Chase, Coming this fall!http://www.gilzu.com
Drop the parentheses. I find that behavior very odd, though...
Map = new char *[x]; 
If this is C++ (and not C), use a vector instead.

This topic is closed to new replies.

Advertisement