array of pointers to struct array

This is a discussion on array of pointers to struct array within the C++ Programming forums, part of the General Programming Boards category; How do you make an array of pointers to point to an array of structures located on the heap? I ...

  1. #1
    Registered User eth0's Avatar
    Join Date
    Dec 2003
    Posts
    164

    array of pointers to struct array

    How do you make an array of pointers to point to an array of structures located on the heap?

    I have been juggling with this for hours but don't seem to be making much progress.

    Code:
    struct MyStruct
    {
      /*members*/
    }
    
    MyStruct *name = new MyStruct[50];
    I now need to set up 50 pointers to these structures. How would I go about this please?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,498
    > How do you make an array of pointers
    MyStruct *array[10];
    An array of 10 pointers to MyStruct

    > point to an array of structures located on the heap?
    array[0] = new MyStruct[50];

    ditto for all the other elements of array
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MergeSort with array of pointers
    By lionheart in forum C Programming
    Replies: 18
    Last Post: 08-01-2008, 10:23 AM
  2. array of pointers to an array pointers
    By onebrother in forum C Programming
    Replies: 2
    Last Post: 07-28-2008, 11:45 AM
  3. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 10:50 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21