fork download
  1. #include <iostream>
  2. struct myBigObject
  3. {
  4. size_t x;
  5. myBigObject() : x() {}
  6. myBigObject(const myBigObject &other)
  7. {
  8. std::cout << "Copy myBigObject" << std::endl;
  9. x = 12;
  10. }
  11. };
  12.  
  13. struct MyClass
  14. {
  15. MyClass(myBigObject s)
  16. : s_(s)
  17. {
  18. std::cout << "x of s : " << s.x << std::endl;
  19. std::cout << "x of s_ : " << s_.x << std::endl;
  20. }
  21. myBigObject s_;
  22. };
  23.  
  24. int main()
  25. {
  26. std::cout << "A:" << std::endl;
  27. MyClass x{ myBigObject() };
  28. std::cout << "B:" << std::endl;
  29. myBigObject y;
  30. MyClass z{ y };
  31. }
Success #stdin #stdout 0s 3340KB
stdin
Standard input is empty
stdout
A:
Copy myBigObject
x of s : 0
x of s_ : 12
B:
Copy myBigObject
Copy myBigObject
x of s : 12
x of s_ : 12