As far as I know, when coming to choose between two candidate functions the compiler will prefer the one that its weakest match is stronger. For example if I have:
void boo(int i, char c);
void boo(double d, int i);
for the following code:
float f = 1.0;
char c = 'c';
boo(f,c);
the second boo
should be prefered because its weakest match is promotion while the first one's is standard type conversion.
But when I try to compile it (using gcc), I get:
error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second.
Any ideas?
Your understanding of overload resolution is wrong. The general rule (when there are more than one argument) is to choose a function for which at least one argument is better (it doesn't matter how much better), and none of the others are worse. In other words, the compiler processes each argument separately, creating a set of "best matches" for it. After this, it takes the union of these sets: if the intersection contains exactly one function, you've won. Otherwise, it's ambiguous.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With