I am creating a program that uses an array of objects declared with
Element * elements = new Element[number];
where an element is a class that has/needs a its own destructor.
when I go to delete this would I use just use array delete, and have the program worry about calling the destructor:
delete [] elements;
or do I call the destructor for each item explicitly with keyword delete:
for(int ii = 0; ii< ArraySize; ii++)
delete elements[ii];
delete [] elements;
Note: I understand that I could probably use something like boost::ptr_vector, but I wanted similar to hashTable functionality (so the for loop would need additional information, but that is outside of the direct scope of this question) which is why I am using a traditional array. I would still like to know which behavior is needed to avoid memory leaks.
The first one. You should
The second one is incorrect and should give you errors if you try to compile it.