Thread: A question about dynamically creating an array of objects

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    31

    A question about dynamically creating an array of objects

    Hello, i want to be able to dynamically create a number of objects based upon user input. I want this array to be accessible by the whole class however i do not understand the notation to do this.

    Currently, in the private attributes section of my class i have:

    object* objectTest

    Then in my constructor i try and create the array using this line, based on how many objects the user enters:

    object* objectTest = new object[numOfObjects];

    This however does not work, i think i just have the wrong notation in the private attributes section.

    i have looked at tutorials however i cannot find the answer

    thanks in advance

  2. #2
    Registered User
    Join Date
    Dec 2004
    Posts
    205
    do this

    objectTest = new object[numOfObjects];

    instead of this

    object* objectTest = new object[numOfObjects];

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    For simple dynamic arrays in C++ you should prefer vectors.

  4. #4
    Registered User
    Join Date
    Mar 2005
    Posts
    31
    thankkkkkkkkkkkkk you i can't believe it was so easy i have been trying to get it working for hours

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Embaracing Array question
    By DavidDobson in forum C Programming
    Replies: 2
    Last Post: 04-06-2009, 10:29 AM
  2. Replies: 4
    Last Post: 11-02-2006, 11:41 AM
  3. Replies: 11
    Last Post: 09-22-2006, 05:21 PM
  4. Replies: 5
    Last Post: 12-05-2002, 02:27 AM
  5. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM