yo/stl/examples/uniqueother.cc
raw| 1 | #include <iostream> |
| 2 | #include <memory> |
| 3 | #include <string> |
| 4 | |
| 5 | using namespace std; |
| 6 | |
| 7 | int main() |
| 8 | { |
| 9 | unique_ptr<string> hello1{ new string{ "Hello world" } }; |
| 10 | unique_ptr<string> hello2{ move(hello1) }; |
| 11 | unique_ptr<string> hello3; |
| 12 | |
| 13 | hello3 = move(hello2); |
| 14 | cout << // *hello1 << '\n' << // would have segfaulted |
| 15 | // *hello2 << '\n' << // same |
| 16 | *hello3 << '\n'; |
| 17 | } |
| 18 | // Displays: Hello world |