fork(2) download
  1. #include <iostream>
  2. using namespace std;
  3. class Foo
  4. {
  5. public:
  6. Foo(){ cout<<"cstor"<<endl; }
  7. ~Foo(){ cout<<"dstor"<<endl; }
  8. Foo(const Foo&){ cout<<"copy"<<endl; }
  9. Foo(Foo&&){ cout<<"move"<<endl; }
  10. };
  11. Foo Get(Foo&& foo)
  12. {
  13. cout<<"Get"<<endl;
  14. return foo;
  15. }
  16. Foo Get2(Foo&& foo)
  17. {
  18. cout<<"Get"<<endl;
  19. return std::move(foo);
  20. }
  21. int main() {
  22. Foo f;
  23. Foo f2;
  24. Get(std::move(f));
  25. cout<<"After Get"<<endl;
  26. Get2(std::move(f2));
  27. cout<<"After Get2"<<endl;
  28. return 0;
  29. }
Success #stdin #stdout 0s 4312KB
stdin
Standard input is empty
stdout
cstor
cstor
Get
copy
dstor
After Get
Get
move
dstor
After Get2
dstor
dstor