By default, the v argument patterns take precedence in overload resolution

If I have a function overloading function like

template<typename T> void f(T&& t, int x = 1);
void f(int x = 0);

      

Which one will be called in preference if I call f

with an integer argument? eg.

f(5);

      

+3


source to share


1 answer


void f(int x = 0);

... During overload resolution, pattern is not always preferred over pattern when the argument type is an exact match (i.e., does not require conversions) - see Β§13.3.3 / 1.



(Note that if there was an overload instead of a template void f(long x = 0);

and callsite remained the same, or if the overload remained the same and callsite instead f(5L);

, the template overload would be called instead.)

+5


source







All Articles