If one tries to delete a pointer that isn't pointing to dynamically allocated memory, is there any way to call delete safely? For instance, I thought it would just throw an exception, in which case I could just use a try-catch block. I tried that, and
1 2 3 4 5 6 7
try
{
int a;
int* p = &a;
delete p;
}
catch(...){}
Exactly. I was planning to have an object which contained an array of pointers to a certain kind of object, some of which would be statically allocated, some of which would be dynamically allocated, but which ones wouldn't be known until runtime, and the destructor would use a loop to delete each member that was dynamically allocated. Thanks for your replies!