Since auto_ptr objects take ownership of the pointer they point to, when a new auto_ptr is constructed from another auto_ptr, the former owner releases it.
Parameters
- p
- Pointer to an object of type X, which is the auto_ptr's template parameter.
If this parameter is 0 the auto_ptr is a null pointer (points to nowhere). - a
- An auto_ptrobject. Ownership is taken from it, therefore, a releases it.
When the types held by the origin and destination auto_ptrs are different, an implicit conversion must be available between their pointers. - r
- An auto_ptr_ref object (a reference to auto_ptr).
X is auto_ptr's template parameter (i.e., the type pointed).
Example
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Output:
p2 points to 10 |
See also
| auto_ptr::operator= | Release and copy auto_ptr (public member function) |
| auto_ptr::reset | Deallocate object pointed and set new value (public member function) |
| auto_ptr::~auto_ptr | Destruct auto_ptr (public member function) |
