If I have a function overload set similar to
template<typename T> void f(T&& t, int x = 1);
void f(int x = 0);
Which of these will be called in preference if I call f with an integer argument? e.g.
f(5);
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
void f(int x = 0);will be called. During overload resolution, a non-template is always preferred over a template when the argument type is an exact match (i.e., needs no conversions) – see §13.3.3/1.(Note that if the non-template overload were instead
void f(long x = 0);and the callsite remained the same, or if the overload remained the same but the callsite were insteadf(5L);, the template overload would be invoked instead.)