Try this:
template<class T> T sum(T a, T b, T c=T())
{
return a + b + c;
}
You can also put in T(5) if you are expecting an integral type and want the default value to be 5.
More Related Contents:
- C++11 does not deduce type when std::function or lambda functions are involved
- Why can’t the template argument be deduced when it is used as template parameter to another template?
- Can someone explain this template code that gives me the size of an array? [duplicate]
- Why can’t I use float value as a template parameter?
- Why not infer template parameter from constructor?
- Explicit specialization in non-namespace scope [duplicate]
- Explicit template instantiation – when is it used?
- Accessing inherited variable from templated parent class [duplicate]
- SFINAE to check for inherited member functions
- Template Constraints C++
- When to use std::forward to forward arguments?
- Function signature-like expressions as C++ template arguments
- How to detect existence of a class using SFINAE?
- C++ template copy constructor on template class
- Template function as a template argument
- SFINAE works differently in cases of type and non-type template parameters
- Making a template parameter a friend?
- C++ static template member, one instance for each template type?
- Can the point-of-instantiation be delayed until the end of the translation unit?
- How to write `is_complete` template?
- How to pass a template function in a template argument list
- How to make std::make_unique a friend of my class
- c++ automatic factory registration of derived types
- Template Function Specialization for Integer Types
- access private member using template trick
- Default member values best practice
- “Permanent” std::setw
- Why does overload of template and non-template function with the “same signature” call the non-template function?
- How to combine std::bind(), variadic templates, and perfect forwarding?
- Fallback variadic constructor – why does this work?