fork download
  1. #include <iostream>
  2. #include <memory>
  3.  
  4. struct A {
  5. const char* name;
  6. A( const char* name_ ):name(name_) { std::cout << "created " << name << "\n"; }
  7. //A(A const&){ std::cout << "copied " << name << "\n"; }
  8. A(const A &&){ std::cout << "moved " << name << "\n"; }
  9. ~A() { std::cout << "dtor " << name << "\n"; }
  10. };
  11.  
  12. A f() {
  13. std::cout << "start of f()\n";
  14. const A r("bob");
  15. std::cout << "body of f()\n";
  16. return r;
  17. }
  18.  
  19. /*
  20. std::unique_ptr<A> g() {
  21.   const auto r = std::make_unique<A>("bill");
  22.   return r;
  23. }
  24. */
  25.  
  26. int main() {
  27. A x = f();
  28. //std::unique_ptr<A> y = g();
  29. }
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
start of f()
created bob
body of f()
dtor bob