I\'m trying to understand the overloading resolution method.
Why is this ambiguous:
void func(double, int, int, double) {}
void func(int, double, double,
Ambiguity is determined by the ranking:
Exact match wins vs Promotion which wins vs Conversion.
In the example:
void func(int, bool, float, int){cout << "int,bool,float,int" << endl;}
void func(int, bool, int, int){cout << "int,int,int,int" << endl;}
int main()
{
func(1,1,3.4,4);
}
Argument 1(1
) is an exact match on both
Argument 2(1
) is an exact match on both
Argument 3(3.4
) can be converted into float and int - Ambiguity Neither is better.
Argument 4(4
) is an exact match on both
But if we did this: func(1,1,3.4f,4);
(3.4f
) is now an exact match!
void func(int, bool, float, int)
then wins the battle.