Thread: dynamic array of pointers?

  1. #1
    Registered User
    Join Date
    Sep 2005

    dynamic array of pointers?

    I have a question. Is it possible to create dynamic array of pointers?I need to create array of pointers inside of class and the array will change in size.

    Normaly i would have

    class player
      Unit *army;
    where Unit is another class and then when i create array of size 2 i use

    army = new Unit[2]
    now instead of Unit i would like *Unit how to do it?

  2. #2
    Registered User
    Join Date
    May 2006
    Of course.

    Foo** MyPtrArray = new Foo*[5];

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    Why not to use vector?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  4. #4
    Registered User
    Join Date
    Sep 2005
    hmm thanks i've tried that before but wrongly put * in new part. Now i know
    thanks a lot

    edit:It's my school project and i'm unfortunatly not allowed to use vectors.
    Last edited by baniakjr; 12-29-2006 at 09:48 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of pointers to an array pointers
    By onebrother in forum C Programming
    Replies: 2
    Last Post: 07-28-2008, 11:45 AM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. Syntax for constant array of array pointers
    By BMintern in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 08:21 AM
  4. Array of struct pointers - Losing my mind
    By drucillica in forum C Programming
    Replies: 5
    Last Post: 11-12-2005, 11:50 PM
  5. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM