In the following :
template<typename Type>
struct MyClass
{
template<typename OtherType> MyClass(const MyClass<OtherType>& x);
template<typename OtherType = Type> void test(const MyClass<OtherType>& x);
};
In the function test what is done between :
Case 1 : The default parameter is priority : the conversion constructor MyClass<Type>(const MyClass<OtherType>& x) is implicitely called and MyClass<Type>::test<Type>(const MyClass<Type>& x) is called.
Case 2 : The deduced parameter is priority : MyClass<Type>::test<Type>(const MyClass<OtherType>& x) is called.
I think that the good answer is the second one, but I’m not sure. Can you confirm me that (and that this situation is well-defined by the standard) ?
EDIT : The test function is called by :
MyClass<double> d;
MyClass<unsigned int> ui;
d.test(ui); // <- So the question is : is ui implicitely
// converted to MyClass<double> or not ?
testwill be called asi.e. there will be no conversion of
uifromMyClass<unsigned int>toMyClass<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: