fork download
  1. #include <iostream>
  2.  
  3. class Example
  4. {
  5. public:
  6. Example();
  7. Example(Example const & orig);
  8. Example & operator= (Example const & orig);
  9. };
  10.  
  11. Example::Example() {}
  12.  
  13. Example::Example(Example const & orig)
  14. {
  15. std::cout << "Copy called." << std::endl;
  16. }
  17.  
  18. Example & Example::operator=(Example const & orig)
  19. {
  20. std::cout << "Assign called." << std::endl;
  21. return *this;
  22. }
  23.  
  24. int main()
  25. {
  26. std::cout << "1" << std::endl;
  27. Example foo;
  28. std::cout << "2" << std::endl;
  29. auto x = Example();
  30. std::cout << "3" << std::endl;
  31. Example y = x;
  32. std::cout << "4" << std::endl;
  33. y = Example();
  34. return 0;
  35. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1
2
3
Copy called.
4
Assign called.