When an overloaded function or overloaded operator is called, the compiler chooses the function declaration with the best match on all arguments from all the function declarations that are visible. The compiler compares the actual arguments of a function call with the formal arguments of all declarations of the function that are visible. For a best match to occur, the compiler must be able to distinguish a function that:
If no such function exists, the call is not allowed. A call to an
overloaded function has three possible outcomes. The compiler can
find:
An ambiguous match occurs when the actual arguments of the
function call match more than one overloaded function.
Argument matching can include performing standard and
user-defined conversions on the arguments to match the actual
arguments with the formal arguments. Only a single user-defined
conversion is performed in a sequence of conversions on an actual
argument. In addition, the best-matching sequence of
standard conversions is performed on an actual argument. The
best-matching sequence is the shortest sequence of conversions
between two standard types. For example , the conversion:
int -> float -> double
can be shortened to the best-matching conversion sequence:
int -> double
because the conversion from int to double is allowed.
Trivial Conversions do not affect the choice of conversion sequence.