Connecting Tech Pros Worldwide Forums | Help | Site Map

deleting an array of objects

Member
 
Join Date: Feb 2007
Posts: 105
#1: Sep 3 '08
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?

Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,379
#2: Sep 3 '08

re: deleting an array of objects


Err... the book says:

Expand|Select|Wrap|Line Numbers
  1. MyClass* array = new MyClass[100];
  2.  
That creates the array. So:
Expand|Select|Wrap|Line Numbers
  1. delete [] array;
  2.  
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.
Reply