Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 默认模板参数与推导模板参数?_C++_C++11_Templates_Standards Compliance_Template Argument Deduction - Fatal编程技术网

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)
}