delete expression
From cppreference.com
Destroys object(s) previously allocated by the new-expression and releases obtained memory area.
Contents |
[edit] Syntax
:: (optional) delete expression
|
(1) | ||||||||
:: (optional) delete[] expression
|
(2) | ||||||||
expression | - | one of the following:
|
1) Destroys one non-array object created by a new-expression.
2) Destroys an array created by a new[]-expression.
[edit] Explanation
Given the pointer evaluated from expression (after possible conversions) as ptr.
1) ptr must be one of
- a null pointer,
- a pointer to a non-array object created by a new-expression, or
- a pointer to a base subobject of a non-array object created by a new-expression.
The pointed-to type of ptr must be similar to the type of the object (or of a base subobject). If ptr is anything else, including if it is a pointer obtained by the array form of new-expression, the behavior is undefined.
2) ptr must be a null pointer or a pointer whose value is previously obtained by an array form of new-expression whose allocation function was not a non-allocating form (i.e. overload (10)).
The pointed-to type of ptr must be similar to the element type of the array object. If ptr is anything else, including if it is a pointer obtained by the non-array form of new-expression, the behavior is