|
-
May 6th, 2001, 07:22 PM
#1
Thread Starter
Addicted Member
the new operator
why want this work
map->LBottom= new TILE_STRUCT [tempheight][tempwidth];
WHat would we do with out Microsoft.
A lot more.
-
May 6th, 2001, 08:09 PM
#2
Frenzied Member
It won't work because you can't allocate a two dimensional array like that. You have to allocate an array of pointers the size of the first dimension, and then for each pointer in the array, allocate memory for the second dimension.
You have to do the same (but backwards) for deleting the memory too, once you've finished with it.
Harry.
"From one thing, know ten thousand things."
-
May 7th, 2001, 05:31 AM
#3
Thread Starter
Addicted Member
you have to do somthing like this
map->LBottom = new TILE_STRUCT[height]
map->LBotoom = new TILE_STRUCT[height][width]
WHat would we do with out Microsoft.
A lot more.
-
May 7th, 2001, 06:15 AM
#4
Monday Morning Lunatic
To allocate:
Code:
map->LBottom = new TILE_STRUCT[height];
for(int i = 0; i < height; i++) {
map->LBottom[i] = new TILE_STRUCT[width];
}
To delete:
Code:
for(int i = 0; i < height; i++) {
delete[] map->LBottom[i];
}
delete[] map->LBottom;
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|