1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// unique_ptr::release example
#include <iostream>
#include <memory>
int main () {
std::unique_ptr<int> auto_pointer (new int);
int * manual_pointer;
*auto_pointer=10;
manual_pointer = auto_pointer.release();
// (auto_pointer is now empty)
std::cout << "manual_pointer points to " << *manual_pointer << '\n';
delete manual_pointer;
return 0;
}
| |