I wrote those two overloads:
int func(int, int) {
return 1;
}
int func(double, double) {
return 2;
}
When I call them with the obvious two calling schemes, i.e. func(1, 1) and func(1.0, 1.0), the first and the second overloaded functions are called, respectively, and when I try to call func(1, 1.0) it gives me an error, but when I cast the 1 to a long long, I don't get an error, and the second overload is the one called.
#include <iostream>
int main()
{
std::cout << func(1, 1); // outputs 1.
std::cout << func(1.0, 1.0); // outputs 2.
// std::cout << func(1, 1.0); // erroneous.
std::cout << func((long long)1, 1.0); // outputs 2.
}
Why is this the case? At first, I thought it was because of some promotion, but I tried a third overload with two floats and I could not get it to be called by calling it like func((int)1, 1.0f). I don't know why wouldn't it be the same, and I don't know why the second overload was called when a long long was passed.