My question is why automatic type conversion does not work when calling overloaded functions in c++. Example code is below:
void test(char t);
void test(short t);
void test(long long t);
void main(){
int a=8;
test(a);
}
If I compile codes above with g++/clang++, an error of function overload ambiguous would occur at
test(a)
Why not the compiler apply automatic type conversion rules here? Variable a in function main() is type of int which should be conversed into type long long to avoid loss of precision. I don't want to write duplicated function for type int or long. Of course I could avoid the error with explicit cast below:
test((long long)a)
However, do I have to use explicit cast every time I need to call test(long long) for parameters of type int or long? Is there any way of making the compiler more smarter?
Thank you for the answers.