[over.match.best.general] (original) (raw)

12 Overloading [over]

12.2 Overload resolution [over.match]

12.2.4 Best viable function [over.match.best]

12.2.4.1 General [over.match.best.general]

Define as the implicit conversion sequence that converts the argument in the list to the type of the parameter of viable function F.

[over.best.ics] defines the implicit conversion sequences and [over.ics.rank]defines what it means for one implicit conversion sequence to be a better conversion sequence or worse conversion sequence than another.

Given these definitions, a viable function is defined to be abetterfunction than another viable function if for all arguments i, is not a worse conversion sequence than , and then

If there is exactly one viable function that is a better function than all other viable functions, then it is the one selected by overload resolution; otherwise the call is ill-formed.105

[Example 8: void Fcn(const int*, short);void Fcn(int*, int);int i;short s = 0;void f() { Fcn(&i, s); // is ambiguous because &i → int* is better than &i → const int* // but s → short is also better than s → int Fcn(&i, 1L); // calls Fcn(int*, int), because &i → int* is better than &i → const int* // and 1L → short and 1L → int are indistinguishable Fcn(&i, 'c'); // calls Fcn(int*, int), because &i → int* is better than &i → const int* // and 'c' → int is better than 'c' → short } — _end example_]

If the best viable function resolves to a function for which multiple declarations were found, and if any two of these declarations inhabit different scopes and specify a default argument that made the function viable, the program is ill-formed.

[Example 9: namespace A { extern "C" void f(int = 5);} namespace B { extern "C" void f(int = 5);} using A::f;using B::f;void use() { f(3); // OK, default argument was not used for viability f(); // error: found default argument twice } — _end example_]