default template arguments are only allowed on a class template; ignored
Default template arguments are allowed only on a class template declaration or definition. Default template arguments may not be used in a function template, or in the definition of a member of a class template.
The following code shows how to use default template arguments and some common mistakes.
/***** Default template arguments are allowed only on a class template declaration or definition. Default template arguments may not be used in a function template, or in the definition of a member of a class template. *****/ #include <stdio.h> // OK : default template argument is allowed on a class template template<class T=int> class A { public: static T f(T a, T b) { return a + b; }; }; class B { public: // C4519 : default template argument is not allowed here template<class T=int> static T f(T a, T b) { return a + b; }; }; // C4519 : default template argument is not allowed here template<class T=int> T f(T a, T b) { return a + b; }; int main() { double a = 3.5, b = 4.25; double d = 0.0; d = f(a, b); // double f(double, double) // Double is deduced from the types of the // arguments to f(). Note that f's default // template argument is ignored. printf("%2.2lf\n", d); // Prints the value 7.75 d = A<>::f(a, b); // int A<>::f(int, int) // Template argument defaults to int. Arguments // are coerced to ints, and an int is returned. printf("%2.2lf\n", d); // Prints the value 7.00 d = B::f(a, b); // Double is deduced from the types of the // arguments to B::f(). Note that B::f's default // template argument is ignored. printf("%2.2lf\n", d); // Prints the value 7.75 return 0; }