test
will be called as
MyClass<double>::test(const MyClass<unsigned int> &)
i.e. there will be no conversion of ui
from MyClass<unsigned int>
to MyClass<double>
.
A default template argument never overrides a given one. It is only used when no template argument is given and the compiler can't deduce it from the function arguments.
From the C++11 Standard:
(§14.8.2/5) The resulting substituted and adjusted function type is used as the type of the function template for template argument deduction. If a template argument has not been deduced, its default template argument, if any, is used. [ Example:
template <class T, class U = double> void f(T t = 0, U u = 0); void g() { f(1, ’c’); // f<int,char>(1,’c’) f(1); // f<int,double>(1,0) f(); // error: T cannot be deduced f<int>(); // f<int,double>(0,0) f<int,char>(); // f<int,char>(0,0) }
— end example ]