Overload resolution
suggest changeRemarks
Overload resolution happens in several different situations
- Calls to named overloaded functions. The candidates are all the functions found by name lookup.
- A call of a class object, such as
obj(args). The candidates are usually the overloaded call operators of that class. - Use of an operator. Member candidates are looked up in the left operand’s class. Non-member candidates are found by ordinary lookup and by argument-dependent lookup, which considers every operand. Built-in operator candidates are included as well.
- Overload resolution to find the correct conversion operator function or constructor to invoke for an initialization
- For non-list direct initialization (
Class c(value)), the candidates are constructors ofClass. - For non-list copy initialization (
Class c = value) and for finding the user defined conversion function to invoke in a user defined conversion sequence. The candidates are the constructors ofClassand if the source is a class object, its conversion operator functions. - For initialization of a non-class from a class object (
Nonclass c = classObject). The candidates are the conversion operator functions of the initializer object. - For initializing a reference with a class object (
R &r = classObject), when the class has conversion operator functions that yield values that can be bound directly tor. The candidates are such conversion operator functions. - For list-initialization of a non-aggregate class object (
Class c{1, 2, 3}), the candidates are the initializer list constructors for a first pass through overload resolution. If this doesn’t find a viable candidate, a second pass through overload resolution is done, with the constructors ofClassas candidates.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents