What's exactly the difference between delete and delete [] ?
I read that delete [] is used when deleting an array,because it deletes all elements in the array and the array itself
And if i do this ??
is it an error ?? compilers never report errors in these cases,butCode:char c = new char[20];
delete c; // instead of delete [] c
is the array really being deleted?
I tried also to create an array of pointers to objects and verify that delete []
calls actually the destructors of all objects in the array before
deleting the array itself
In order to do that i put a printf in the class' destructor,but it wasn't displayed :confused:
How do you use delete [] ?Code:SomeClass **objectptr = new SomeClass*[20];
// create the objects
for(int i = 0;i < 20;i++)
objectptr[i] = new SomeClass();
//..
delete [] objectptr; // this doesn't delete the objects...but just
// the memory occupied by their pointers