fork download
  1. struct MyClass
  2. {
  3. MyClass() = default;
  4. MyClass(int)
  5. {
  6. }
  7. MyClass operator+(MyClass const &other) const
  8. {
  9. //...
  10. return MyClass{/**/};
  11. }
  12. };
  13.  
  14. int main()
  15. {
  16. MyClass a, b;
  17. auto c = a + b; //fine
  18. auto d = a + 3; //fine
  19. auto e = 3 + a; //error
  20. }
  21.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:19:13: error: no match for 'operator+' (operand types are 'int' and 'MyClass')
  auto e = 3 + a; //error
             ^
stdout
Standard output is empty