fork download
  1. #include <iostream>
  2.  
  3. class Foo
  4. {
  5. private:
  6. int m_data;
  7.  
  8. public:
  9. Foo(int data)
  10. : m_data(data)
  11. {
  12.  
  13. }
  14.  
  15. Foo& operator=(const Foo& other)
  16. {
  17. if (this == &other)
  18. {
  19. return *this;
  20. }
  21.  
  22. m_data = other.m_data;
  23. return *this;
  24. }
  25.  
  26. int GetData()
  27. {
  28. return m_data;
  29. }
  30. };
  31.  
  32. int main()
  33. {
  34. auto a = Foo(42);
  35. auto b = Foo(24);
  36. auto c = Foo(10);
  37.  
  38. a = b = c;
  39.  
  40. std::cout << &a << ": " << a.GetData() << std::endl;
  41. std::cout << &b << ": " << b.GetData() << std::endl;
  42. std::cout << &c << ": " << c.GetData() << std::endl;
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
0xbffa0704: 10
0xbffa0708: 10
0xbffa070c: 10