error message - assertion failed!!

i need help about my oop code..
i got this message after i delete allocated class object,
should i check the deleting? if it's object what is the correct way to delete/delete[]?
theCars[nToDel] is a static array of pointers

bool Cars::deleteElement(int nToDel)
if (theCars[nToDel] != NULL)
delete[] theCars[nToDel];
return true;
return false;
If you did not use new[] to create the array, you MUST NOT use delete[] to destroy it.

If you have a static array (as in, not dynamically allocated), then you do not need to delete anything. It will clean up after itself. You only need to delete[] things that you new[]'d*

*and even then... if you 'new' something, you should put it in a smart pointer so you don't have to delete it. But you probably didn't learn about them yet because C++ is taught poorly </mini rant>
thanks for the answer, but i have static array of pointers which point to objects and i want deleting this object not the array,the object is allocated, i tried calling the destructor but it didn't solve the problem..

if i called the destructor of the object i got this message:
Unhandled exception at 0x002743a6 in oop_ex1.exe: 0xC0000005: Access violation reading location 0x00000000.
Last edited on
Do not call the destructor directly. You only do that if you are writing your own memory allocation and management code (you're not).

Anyway... as for your problem... show me how theCars is defined... and how you are allocating memory for it. Because how you are doing that determines how you have to delete it.
Topic archived. No new replies allowed.