Possible Duplicate:
delete vs delete[] operators in C++
I've written a class that contains two pointers, one is char* color_
and one in vertexesset* vertex_
where vertexesset
is a class I created. In the destractor I've written at start
delete [] color_;
delete [] vertex_;
When It came to the destructor it gave me a segmentation fault.
Then I changed the destructor to:
delete [] color_;
delete vertex_;
And now it works fine. What is the difference between the two?
You delete []
when you new
ed an array type, and delete
when you didn't. Examples:
typedef int int_array[10];
int* a = new int;
int* b = new int[10];
int* c = new int_array;
delete a;
delete[] b;
delete[] c; // this is a must! even if the new-line didn't use [].