fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. #include <iostream>
  6.  
  7. class MyClass {
  8. public:
  9. MyClass() { std::cout << "Default constructor called" << std::endl; }
  10. MyClass(const MyClass& other) { std::cout << "Copy constructor called" << std::endl; }
  11. MyClass(MyClass&& other) { std::cout << "Move constructor called" << std::endl; }
  12.  
  13. MyClass& operator=(const MyClass& other) {
  14. std::cout << "Copy assignment operator called" << std::endl;
  15. return *this;
  16. }
  17.  
  18. MyClass& operator=(MyClass&& other) {
  19. std::cout << "Move assignment operator called" << std::endl;
  20. return *this;
  21. }
  22. };
  23.  
  24.  
  25.  
  26. int main() {
  27. MyClass a;
  28. MyClass& a_ref = a;
  29. MyClass b;
  30. a_ref = b;
  31. return 0;
  32. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
Default constructor called
Default constructor called
Copy assignment operator called