fork(1) download
  1. #include <iostream>
  2.  
  3. class Foo
  4. {
  5. public:
  6. Foo() = default;
  7. Foo(const Foo&)
  8. {
  9. std::cout << "Look mom, I am being copied!" << std::endl;
  10. }
  11. Foo(Foo&&)
  12. {
  13. std::cout << "Look mom, I am being moved!" << std::endl;
  14. }
  15. };
  16.  
  17. void bar(Foo f) {}
  18.  
  19. int main() {
  20. Foo f;
  21. bar(f); // Copied
  22. bar(std::move(f)); // Moved
  23. bar(Foo{}); // Elided
  24. return 0;
  25. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
Look mom, I am being copied!
Look mom, I am being moved!