1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
There are three ways to hi(unique_ptr: defining) define tt(unique_ptr)
objects. Each definition contains the usual tt(<type>) specifier between
angle brackets:
itemization(
it() The default constructor simply creates a tt(unique_ptr) object that
does not point to a particular block of memory. Its pointer is initialized to
0 (zero):
verb(unique_ptr<type> identifier;)
This form is discussed in section ref(UNIQUEPLAIN).
it() The em(move constructor) initializes an tt(unique_ptr) object.
Following the use of the move constructor its tt(unique_ptr) argument no
longer points to the dynamically allocated memory and its pointer data member
is turned into a zero-pointer:
verb(unique_ptr<type> identifier(another unique_ptr for type);)
This form is discussed in section ref(UNIQUEMOVE).
it() The form that is used most often initializes a tt(unique_ptr) object
to the block of dynamically allocated memory that is passed to the object's
constructor. Optionally ti(deleter) can be provided. A (free) function (or
function object) receiving the tt(unique_ptr)'s pointer as its argument can be
passed as deleter. It is supposed to return the dynamically allocated
memory to the common pool (doing nothing if the pointer equals zero).
verb(unique_ptr<type> identifier (new-expression [, deleter]);)
This form is discussed in section ref(UNIQUENEW).
)
|