fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Foo
  5. {
  6. public:
  7. operator int () { return 5; }
  8. operator long () { return 100; }
  9. };
  10.  
  11. int main() {
  12. Foo foo1, foo2;
  13. int var1 = foo1 + foo2;
  14. long var2 = foo1 + foo2;
  15.  
  16. cout << var1 << endl << var2 << endl;
  17.  
  18. return 0;
  19. }
Compilation error #stdin compilation error #stdout 0s 3412KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:13:18: error: ambiguous overload for 'operator+' (operand types are 'Foo' and 'Foo')
  int var1 = foo1 + foo2;
                  ^
prog.cpp:13:18: note: candidate: operator+(int, int) <built-in>
prog.cpp:13:18: note: candidate: operator+(int, long int) <built-in>
prog.cpp:13:18: note: candidate: operator+(long int, int) <built-in>
prog.cpp:13:18: note: candidate: operator+(long int, long int) <built-in>
prog.cpp:14:19: error: ambiguous overload for 'operator+' (operand types are 'Foo' and 'Foo')
  long var2 = foo1 + foo2;
                   ^
prog.cpp:14:19: note: candidate: operator+(int, int) <built-in>
prog.cpp:14:19: note: candidate: operator+(int, long int) <built-in>
prog.cpp:14:19: note: candidate: operator+(long int, int) <built-in>
prog.cpp:14:19: note: candidate: operator+(long int, long int) <built-in>
stdout
Standard output is empty