#include <iostream>
using namespace std;
class Foo
{
public:
operator int () { return 5; }
operator long () { return 100; }
};
int main() {
Foo foo1, foo2;
int var1 = foo1 + foo2;
long var2 = foo1 + foo2;
cout << var1 << endl << var2 << endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKY2xhc3MgRm9vCnsKcHVibGljOgoJb3BlcmF0b3IgaW50ICgpIHsgcmV0dXJuIDU7IH0KCW9wZXJhdG9yIGxvbmcgKCkgeyByZXR1cm4gMTAwOyB9Cn07CgppbnQgbWFpbigpIHsKCUZvbyBmb28xLCBmb28yOwoJaW50IHZhcjEgPSBmb28xICsgZm9vMjsKCWxvbmcgdmFyMiA9IGZvbzEgKyBmb28yOwoJCgljb3V0IDw8IHZhcjEgPDwgZW5kbCA8PCB2YXIyIDw8IGVuZGw7CgkKCXJldHVybiAwOwp9
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>