Implicit sequence of conversions with function overloading

I don't understand how the compiler picks the best candidates. For example, let's say it has the following code:

int function(double, int, int){...}
int function(int, double, double){...}


If the second function needs to convert two variables and the first needs to convert only one variable, why isn't the first one selected? Why is this an ambiguous situation?


source to share

1 answer

Why is this an ambiguous situation?

According to Β§ 13.3.3 / 1,

Given these definitions, a viable function F1

is defined to be better than another viable function F2

if, for all arguments i, ICS i ( F1

) is not a worse conversion sequence than ICS i ( F2

, and then

- for some argument j, ICS j ( F1

) is a better conversion than ICS j ( F2

), or if not,

- [...]

Therefore, the type call is function(0., 0., 0.)

ambiguous; Neither overload is better than the other.

Consider the deduction of a template argument from a function call - if a template parameter is T

used in multiple function parameters (e.g. T a, T b, T c

), and for two call arguments, it is deduced as int

, but for the third, how double

should it really result in a successful deduction with T=int


Overload resolution ignores best matches and calls out a winner - that wouldn't be decisive enough.

Imagine a puzzle - is it a piece that really fits better for a space if it fits better on both ends but worse on the other?



All Articles