fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. std::unique_ptr<std::string> func ()
  5. {
  6. std::unique_ptr<std::string> ptr(new std::string("hey"));
  7. return ptr;
  8. }
  9.  
  10. std::unique_ptr<std::string> func2(std::unique_ptr<std::string> ptr)
  11. {
  12. return ptr;
  13. }
  14.  
  15. int main()
  16. {
  17. auto name = func();
  18. std::cout<<*name<<std::endl;
  19. std::cout<<"Name ptr: "<<name.get()<<std::endl;
  20.  
  21. auto name2 = func2(std::move(name));
  22. std::cout<<*name2<<std::endl;
  23.  
  24. std::cout<<"Name ptr: "<<name.get()<<std::endl;
  25. std::cout<<"Name2 ptr: "<<name2.get()<<std::endl;
  26. return 0;
  27. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
hey
Name ptr: 0x977fa10
hey
Name ptr: 0
Name2 ptr: 0x977fa10