Possible Duplicate:
What is the difference between delete and delete[]?
When I was taught C++, this was a long time ago. I was told to never use delete
but delete[]
as performing delete[]
on a single object will be equivalent to delete
. Knowing not to trust teachers too much I wonder, Is this true?
Is there ever a reason to call delete
instead of delete[]
?
I've scanned the possibly related questions in SO, but haven't found any clear answer.
From the standard (5.3.5/2) :
In the first alternative (delete object), the value of the operand of delete shall be a pointer to a non-array object or a pointer to a sub-object (1.8) representing a base class of such an object (clause 10). If not, the behavior is undefined.
In the second alternative (delete array), the value of the operand of delete shall be the pointer value which resulted from a previous array new-expression. If not, the behavior is undefined.
So no : they are in no way equivalent !