Thread: Creating an array of object pointers

  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, 08: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, 02:31 PM
  4. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  5. Replies: 4
    Last Post: 09-12-2001, 02:05 PM