I am asking about the static binding of the function in C++. What’s the data type conversion rules for the function binding.
Suppose we have
void func(int x);
void func(long x);
void func(float x);
void func(double x);
void func(char x);
and I have one function in main
func(1)
I know the function func(int x) will be called. I am curious about the rules of that.
Is it always the best match?
Does the order of declaration matter?
In any case the data type conversion will be applied?
What’s the concern when the rules are designed?
Yes:
1is anint. If an appropriate overload exists, it will be taken since this minimizes the number of necessary implicit conversions (none).No. However, it matters whether a function has been declared before the call is made. If the function is declared after the call, it will not be taken into consideration for overload resolution.
There’s no conversion here because
intis an exact match. Conversions only come into play when there’s no exact match available.Well, it’s the only rule that makes sense, isn’t it?