dynamic array of pointers?

This is a discussion on dynamic array of pointers? within the C++ Programming forums, part of the General Programming Boards category; I have a question. Is it possible to create dynamic array of pointers?I need to create array of pointers inside ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    20

    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

    Code:
    class player
    {
      private:
      Unit *army;
    }
    where Unit is another class and then when i create array of size 2 i use

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

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

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

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    Why not to use vector?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    20
    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, 12:45 PM
  2. Replies: 2
    Last Post: 07-11-2008, 08:39 AM
  3. Syntax for constant array of array pointers
    By BMintern in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 09: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

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