Creating an array of object pointers

This is a discussion on Creating an array of object pointers within the C++ Programming forums, part of the General Programming Boards category; I've declared a class called CDog and want to create an array of object pointers of this type (CDog). How ...

  1. #1
    Unregistered
    Guest

    Creating an array of object pointers

    I've declared a class called CDog and want to create an array of object pointers of this type (CDog). How would I do this? I.e. I want to create the following:

    int intArray[3] = {0}; // array of 3 integers
    CDog *dog = new CDog.... /// how would I create an array AND delete the array of object pointers?

    Thanx,

    David

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    155
    CDog * dog = new CDog[3];

    will create an array of three items of type CDog. CDog should have appropriate (usually a default) constructor(s) for the new operator to call.

    delete [] dog;

    will call the destructor for CDog as many times as it takes to delete all the items of the type declared in dog.

  3. #3
    Unregistered
    Guest

    Thank you

    thx!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Syntax for constant array of array pointers
    By BMintern in forum C Programming
    Replies: 4
    Last Post: 05-14-2008, 09:21 AM
  2. dynamically creating an array of pointers
    By cs32 in forum C Programming
    Replies: 4
    Last Post: 02-06-2008, 09:42 AM
  3. Array of Pointers to Arrays
    By Biozero in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 03:31 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 09:31 AM
  5. Replies: 4
    Last Post: 09-12-2001, 03:05 PM

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