Exact match

suggest change

An overload without conversions needed for parameter types or only conversions needed between types that are still considered exact matches is preferred over an overload that requires other conversions in order to call.

void f(int x);
void f(double x);
f(42); // calls f(int)

When an argument binds to a reference to the same type, the match is considered to not require a conversion even if the reference is more cv-qualified.

void f(int& x);
void f(double x);
int x = 42;
f(x); // argument type is int; exact match with int&

void g(const int& x);
void g(int x);
g(x); // ambiguous; both overloads give exact match

For the purposes of overload resolution, the type “array of T” is considered to match exactly with the type “pointer to T”, and the function type T is considered to match exactly with the function pointer type T*, even though both require conversions.

void f(int* p);
void f(void* p);

void g(int* p);
void g(int (&p)[100]);

int a[100];
f(a); // calls f(int*); exact match with array-to-pointer conversion
g(a); // ambiguous; both overloads give exact match

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Overload resolution:
* Exact match

Table Of Contents
8 Arrays
11 Loops
39 Streams
51 Unions
56 Lambdas
60 SFINAE
62 RAII
67 Sorting
72 Overload resolution
84 RTTI
87 Scopes
104 Profiling
107 Recursion
117 Iteration
125 Alignment
134 Semaphore
136 Debugging
139 Mutexes
142 decltype