113 Contributors: 4 Friday, May 5, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial:
Roadmap: roadmap

Overload resolution


Overload resolution happens in several different situations

  • Calls to named overloaded functions. The candidates are all the functions found by name lookup.
  • Calls to class object. The candidates are usually all the overloaded function call operators of the class.
  • Use of an operator. The candidates are the overloaded operator functions at namespace scope, the overloaded operator functions in the left class object (if any) and the built-in operators.
  • 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 of Class.
    • 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 of Class and 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 to r. 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 of Class as candidates.

Related Examples