In a function template specialization, a template argument is optional if the
compiler can deduce it from the type of the function arguments. The
following example demonstrates this:
template<class T> class X { }; template<class T> void f(X<T>); template<> void f(X<int>);
The explicit specialization template<> void f(X<int>) is equivalent to template<> void f<int>(X<int>).
You cannot specify default function arguments in a declaration or a definition for any of the following:
For example, the compiler will not allow the following code:
template<class T> void f(T a) { }; template<> void f<int>(int a = 5) { }; template<class T> class X { void f(T a) { } }; template<> void X<int>::f(int a = 10) { };
Related References