fork(1) download
  1. #include <iostream>
  2.  
  3. struct Bar {
  4. Bar() { std::cout << "create\n"; }
  5. Bar(Bar const&) { std::cout << "copy\n"; }
  6. Bar(Bar&&) { std::cout << "move\n"; }
  7. ~Bar() { std::cout << "destroy\n"; }
  8. };
  9.  
  10. void fooA(Bar const& bar) {
  11. Bar bar_cpy(bar);
  12. }
  13.  
  14. void fooB(Bar bar) {
  15. }
  16.  
  17. int main() {
  18. ::std::cout << "by-reference then copy\n";
  19. fooA(Bar());
  20.  
  21. ::std::cout << "\nby-value\n";
  22. fooB(Bar());
  23. }
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
by-reference then copy
create
copy
destroy
destroy

by-value
create
destroy