unique.cpp 421 B

12345678910111213141516171819202122
  1. #include <iostream>
  2. #include <string>
  3. #include <memory>
  4. using namespace std;
  5. unique_ptr<string> demo(const char * s)
  6. {
  7. unique_ptr<string> temp(new string(s));
  8. return temp;
  9. }
  10. int main()
  11. {
  12. unique_ptr<string> ps1, ps2;
  13. ps1 = demo("Uniquely special");
  14. ps2 = move(ps1); // enable assignment
  15. ps1 = demo(" and more");
  16. cout << *ps2 << *ps1 << endl;
  17. // cin.get();
  18. return 0;
  19. }