fork download
  1. #include <iostream>
  2.  
  3. class A
  4. {
  5. public:
  6. A(std::string str)
  7. : m_data(str)
  8. {
  9. std::cout << "Ctor" << std::endl;
  10. }
  11.  
  12. A(const A& rhs)
  13. : m_data(rhs.m_data)
  14. {
  15. std::cout << "Copy ctor" << std::endl;
  16. }
  17.  
  18. A(A&& rhs) noexcept
  19. : m_data(std::move(rhs.m_data))
  20. {
  21. std::cout << "Move ctor" << std::endl;
  22. }
  23.  
  24. void print()
  25. {
  26. std::cout << m_data << std::endl;
  27. }
  28.  
  29. private:
  30. std::string m_data;
  31. };
  32.  
  33.  
  34. int main()
  35. {
  36. A one("one");
  37. A two(one);
  38.  
  39. A three = std::move(one);
  40.  
  41. one.print();
  42. two.print();
  43. three.print();
  44.  
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
Ctor
Copy ctor
Move ctor

one
one