Name
operator delete — Global operator delete
Synopsis
void operator delete(void* ptr) throw( ); void operator delete[](void* ptr) throw( ); void operator delete(void* ptr, const std::nothrow_t&) throw( ); void operator delete[](void* ptr, const std::nothrow_t&) throw( ); void operator delete(void* ptr, void*) throw( ); void operator delete[](void* ptr, void*) throw( );
The global operator
delete
function is called from a
delete
expression to free memory.
The memory, which ptr
points to,
must have been returned by a corresponding call to operator
new
or be a null pointer. You must not
call operator
delete
more than once for the same
pointer. If ptr
is null, operator
delete
returns without doing
anything.
The first two versions of operator
delete
free the memory that ptr
points to, which must have been
allocated by calling the plain form of operator
new
. These forms of operator
delete
are called from a delete
expression. The first is called for
a scalar delete
, and the second
is called for an array delete[]
.
The remaining forms are called only when the corresponding
placement new
expression throws
an exception during construction. The nothrow
functions free the memory that
ptr
points to. The last two forms
do nothing. See the new
expression in Chapter 3 to
learn how and when placement operator
delete
is called.
Unlike other identifiers in the standard library, operator
delete
is global and is not in the
std
namespace. Also, unlike with other functions in the standard library, you can provide ...
Get C++ In a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.