I have a pointer to a array of pointers that I want to be safely deleted no matter where exceptions happen. Right now I have to loop through the array and call delete on each item and then call delete[] on the array. auto_ptr just seems to delete the the array but not the individual pointers inside the array. Is there a simple solution for this?
double** desc = new MyObject*[size_out];
for (int i=0; i<size_out; i++)
desc[i] = new MyObject();
for (int i=0; i<size_out; i++)
delete desc[i];
delete [] desc;
Thanks
I think what you will have to do is create a stack object which takes a pointer to an array of pointers and does the cleaning up in its destructor. Something like:
There is no smart pointer that does this, so you just have to do it yourself.