fork download
  1. #include <iostream>
  2.  
  3. struct A {
  4. const char* name;
  5. A( const char* name_ ):name(name_) { std::cout << "created " << name << "\n"; }
  6. A(A const&){ name="c"; std::cout << "copied " << "\n"; }
  7. A(A &&){ name="m"; std::cout << "moved " << "\n"; }
  8. };
  9.  
  10. A f() {
  11. std::cout << "start of f()\n";
  12. A r("bob");
  13. std::cout << "body of f()\n";
  14. return r;
  15. }
  16.  
  17. int main() {
  18. A x = f();
  19. std::cout << "end" << x.name << "\n";
  20. }
  21.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
start of f()
created bob
body of f()
endbob