fork download
  1. struct S
  2. {
  3. S& operator =(const S& rhs) & // note the final &
  4. // to restrict this to be lvalue
  5. {
  6. // implementation
  7. return *this;
  8. }
  9. };
  10.  
  11. S operator +(const S& lhs, const S& rhs);
  12.  
  13. int main()
  14. {
  15. S a, b, c;
  16.  
  17. (a + b) = c;
  18. return 0;
  19. }
  20.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:17:13: error: no match for ‘operator=’ (operand types are ‘S’ and ‘S’)
     (a + b) = c;
             ^
prog.cpp:17:13: note: candidate is:
prog.cpp:3:8: note: S& S::operator=(const S&) &
     S& operator =(const S& rhs) & // note the final &
        ^
prog.cpp:3:8: note:   no known conversion for implicit ‘this’ parameter from ‘S’ to ‘S&’
stdout
Standard output is empty