fork download
  1. #include <iostream>
  2.  
  3. struct T1
  4. {
  5. int x = 0;
  6. };
  7.  
  8. bool operator == (T1 lhs, int rhs)
  9. {
  10. return lhs.x == rhs;
  11. }
  12.  
  13. bool operator == (int lhs, T1 rhs)
  14. {
  15. return lhs == rhs.x;
  16. }
  17.  
  18. struct T2
  19. {
  20. int x;
  21.  
  22. bool operator == (int rhs)
  23. {
  24. return this->x == rhs;
  25. }
  26.  
  27. bool operator == (T2 rhs)
  28. {
  29. return this->x == rhs.x;
  30. }
  31. };
  32.  
  33. int main()
  34. {
  35. std::cout << (T1() == 0) << std::endl;
  36. std::cout << (0 == T1()) << std::endl;
  37.  
  38. std::cout << (T2() == 0) << std::endl;
  39. std::cout << (0 == T2()) << std::endl;
  40. }
Compilation error #stdin compilation error #stdout 0s 3296KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:39:18: error: no match for ‘operator==’ (operand types are ‘int’ and ‘T2’)
  std::cout << (0 == T2()) << std::endl;
                  ^
prog.cpp:39:18: note: candidates are:
prog.cpp:8:6: note: bool operator==(T1, int)
 bool operator == (T1 lhs, int rhs)
      ^
prog.cpp:8:6: note:   no known conversion for argument 1 from ‘int’ to ‘T1’
prog.cpp:13:6: note: bool operator==(int, T1)
 bool operator == (int lhs, T1 rhs)
      ^
prog.cpp:13:6: note:   no known conversion for argument 2 from ‘T2’ to ‘T1’
stdout
Standard output is empty