I have an overloaded method "divFnc". When I call it at FIRST_CALL there is no error, but when I call the SECOND_CALL there is an error (call is ambiguous). Why?
1 2 3 4 5 6 7 8 9 10 11 12 13
int divFnc(int a, int b) {
return a / b;
}
float divFnc(float a, float b) {
return a / b;
}
int main() {
int c = divFnc(10, 5); //FIRST_CALL
float d = divFnc(10.4, 5.4); //SECOND_CALL
return 0;
}
one of the compilers I use (IBM XL C/C++) likes to explain overload abiguities in detail:
"test.cc", line 11.14: 1540-0219 (S) The call to "divFnc" has no best match.
"test.cc", line 11.21: 1540-1229 (I) Argument number 1 is an rvalue of type "double".
"test.cc", line 11.27: 1540-1229 (I) Argument number 2 is an rvalue of type "double".
"test.cc", line 5.7: 1540-1202 (I) No candidate is better than "divFnc(float, float)".
"test.cc", line 11.21: 1540-1231 (I) The conversion from argument number 1 to "float" uses "a floating point conversion".
"test.cc", line 11.27: 1540-1231 (I) The conversion from argument number 2 to "float" uses "a floating point conversion".
"test.cc", line 1.5: 1540-1202 (I) No candidate is better than "divFnc(int, int)".
"test.cc", line 11.21: 1540-1231 (I) The conversion from argument number 1 to "int" uses "a floating point-integral conversion".
"test.cc", line 11.27: 1540-1231 (I) The conversion from argument number 2 to "int" uses "a floating point-integral conversion".
(and, as implied, floating point conversions and float-integral conversions have equal ranks w.r.t overload resolution)
I am terribly sorry but I still not get the why. The numbers (10.4 and 5.4) are floats so how can the function with int parameters be considered as a candidate?