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. void operator=(const Foo& other)
  16. {
  17. m_data = other.m_data;
  18. }
  19.  
  20. int GetData()
  21. {
  22. return m_data;
  23. }
  24. };
  25.  
  26. int main()
  27. {
  28. auto a = Foo(42);
  29. auto b = Foo(24);
  30. auto c = Foo(10);
  31.  
  32. a = b = c;
  33.  
  34. std::cout << &a << ": " << a.GetData() << std::endl;
  35. std::cout << &b << ": " << b.GetData() << std::endl;
  36. std::cout << &c << ": " << c.GetData() << std::endl;
  37.  
  38. return 0;
  39. }
Compilation error #stdin compilation error #stdout 0s 3412KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:32:4: error: no match for 'operator=' (operand types are 'Foo' and 'void')
  a = b = c;
    ^
prog.cpp:15:7: note: candidate: void Foo::operator=(const Foo&)
  void operator=(const Foo& other)
       ^
prog.cpp:15:7: note:   no known conversion for argument 1 from 'void' to 'const Foo&'
stdout
Standard output is empty