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