C++ 默认模板参数与推导模板参数?
在以下方面:C++ 默认模板参数与推导模板参数?,c++,c++11,templates,standards-compliance,template-argument-deduction,C++,C++11,Templates,Standards Compliance,Template Argument Deduction,在以下方面: template<typename Type> struct MyClass { template<typename OtherType> MyClass(const MyClass<OtherType>& x); template<typename OtherType = Type> void test(const MyClass<OtherType>& x); }; test将被称为
template<typename Type>
struct MyClass
{
template<typename OtherType> MyClass(const MyClass<OtherType>& x);
template<typename OtherType = Type> void test(const MyClass<OtherType>& x);
};
test
将被称为
MyClass<double>::test(const MyClass<unsigned int> &)
-[结束示例]
test
将被称为
MyClass<double>::test(const MyClass<unsigned int> &)
-[结束示例]
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)
}