deleting an array of objects

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mickey22
    New Member
    • Feb 2007
    • 105

    deleting an array of objects

    Could you please give an example how to create and an array of objects and how to delete them ?

    Do I have to create for loop to delete all of them?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Err... the book says:

    [code=cpp]
    MyClass* array = new MyClass[100];
    [/code]

    That creates the array. So:
    [code=cpp]
    delete [] array;
    [/code]
    should delete the array.

    Constructors and destructors will be called as needed.

    Since this is an array, you cannot delete specific members. If you have that kind of requirement, use the vector container.

    Comment

    Working...