【发布时间】:2012-11-18 06:49:45
【问题描述】:
如下:
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:默认参数为priority:隐式调用转换构造函数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 ?
【问题讨论】:
标签: c++ c++11 templates standards-compliance template-argument-deduction