fork(3) download
  1. #include <iostream>
  2.  
  3. struct A
  4. {
  5. A() {}
  6. A( const A& ) { std::cout << "A::copy_constructor is called to make a copy\n" ; }
  7. A( A&& ) { std::cout << "in this program, this message will not be printed\n" ; }
  8. };
  9.  
  10. void foo( A object ) { std::cout << "foo has recieved a copy of an object\n" ; }
  11. A bar() { std::cout << "bar - about to return an object by value\n" ; static A a ; return a ; }
  12.  
  13. int main()
  14. {
  15. std::cout << "about to call bar\n" ;
  16. A object = bar() ;
  17. std::cout << "bar has returned\n" ;
  18.  
  19. std::cout << "\n\nabout to call foo\n" ;
  20. foo(object) ;
  21. }
  22.  
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
about to call bar
bar - about to return an object by value
A::copy_constructor is called to make a copy
bar has returned


about to call foo
A::copy_constructor is called to make a copy
foo has recieved a copy of an object