fork(14) 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. };
  8.  
  9. void foo( A object ) { std::cout << "foo has recieved a copy of an object\n" ; }
  10. A bar() { std::cout << "bar - about to return an object by value\n" ; static A a ; return a ; }
  11.  
  12. int main()
  13. {
  14. std::cout << "about to call bar\n" ;
  15. A object = bar() ;
  16. std::cout << "bar has returned\n" ;
  17.  
  18. std::cout << "\n\nabout to call foo\n" ;
  19. foo(object) ;
  20. }
  21.  
Success #stdin #stdout 0s 2852KB
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