1
在以下幾點:默認vs推測模板參數?
template<typename Type>
struct MyClass
{
template<typename OtherType> MyClass(const MyClass<OtherType>& x);
template<typename OtherType = Type> void test(const MyClass<OtherType>& x);
};
在功能test
所做的事情之間:
案例1:默認參數是優先級:轉換構造MyClass<Type>(const MyClass<OtherType>& x)
被隱含調用,MyClass<Type>::test<Type>(const MyClass<Type>& x)
是調用。
案例2:推導出的參數優先:調用MyClass<Type>::test<Type>(const MyClass<OtherType>& x)
。
我認爲很好的答案是第二個,但我不確定。你能證實我的看法嗎(並且這種情況是由標準定義的)?
編輯:測試函數的調用:
MyClass<double> d;
MyClass<unsigned int> ui;
d.test(ui); // <- So the question is : is ui implicitely
// converted to MyClass<double> or not ?