Is it possible to define the default value for variables of a template function in C++?
Something like below:
template<class T> T sum(T a, T b, T c=????)
{
return a + b + c;
}
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.
Try this:
You can also put in T(5) if you are expecting an integral type and want the default value to be 5.