1 2 3 4 5 6 7 8 9 10 11 12 13 14 | void f(int x) { } int f(const int & x) { return x; } int main() { // ambiguous call f(42); // even when we call it using a const ref, it's ambiguous, so no hack possible... int arg = 42; const int &argR = arg; f(argR); } |
CnZvaWQgZihpbnQgeCkgeyB9CmludCBmKGNvbnN0IGludCAmIHgpIHsgcmV0dXJuIHg7IH0KCmludCBtYWluKCkKewogICAgLy8gYW1iaWd1b3VzIGNhbGwKICAgIGYoNDIpOwogICAgCiAgICAvLyBldmVuIHdoZW4gd2UgY2FsbCBpdCB1c2luZyBhIGNvbnN0IHJlZiwgaXQncyBhbWJpZ3VvdXMsIHNvIG5vIGhhY2sgcG9zc2libGUuLi4KICAgIGludCBhcmcgPSA0MjsKICAgIGNvbnN0IGludCAmYXJnUiA9IGFyZzsKICAgIGYoYXJnUik7Cn0=
prog.cpp: In function 'int main()': prog.cpp:8:9: error: call of overloaded 'f(int)' is ambiguous prog.cpp:2:6: note: candidates are: void f(int) prog.cpp:3:5: note: int f(const int&) prog.cpp:13:11: error: call of overloaded 'f(const int&)' is ambiguous prog.cpp:2:6: note: candidates are: void f(int) prog.cpp:3:5: note: int f(const int&)
-
result: Compilation error (maybe you wish to see an example for C++11)


