Results 1 to 4 of 4

Thread: the new operator

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204

    the new operator

    why want this work
    map->LBottom= new TILE_STRUCT [tempheight][tempwidth];
    WHat would we do with out Microsoft.
    A lot more.

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    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."

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    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.

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width