I have an array of pointers to objects, and I wish to delete an object pointed to by one of the elements. However, when I try to do this using delete MyPtrArray[2]; my program crashes at runtime. The object pointed to by MyPtrArray[2] definitely exists, as I can access the object's data via the pointer. Am I using delete incorrectly here?

Thanks!

03-04-2004

jlou

The code below works fine, so you'll have to show more of your code to see what you are doing wrong.

By the way, do you know when your program crashes at run time? Is it after or during the delete. If it is after, it is quite possible that you are trying to use the pointer that you deleted after you delete it.

03-04-2004

Codeplug

Or perhaps the object's desctructor is causing the problem......
Use your debugger to pinpoint where the crash is occuring for more clues.

gg

03-04-2004

Nereus

Thanks CodePlug, you were exactly right, it was a problem in the destructor. I guess I should've checked there first...