【发布时间】:2018-11-10 19:12:43
【问题描述】:
考虑以下几个类:
template <typename T1, typename T2>
class A{
public:
// ...
};
template<typename _T>
struct alias { typedef A<int,_T> intA; };
class B{
public:
// ...
template <typename _T> B& operator=(const typename alias<_T>::intA& _arg) { };
};
当我尝试将 A<int,int> 类的对象分配给 B 类的对象时,出现以下编译错误:
template argument deduction/substitution failed: couldn't deduce template parameter ‘_T’
有没有其他方法可以使用 typedef 作为B::operator=() 的输入参数??
【问题讨论】:
-
这不是问题,但是以下划线开头后跟大写字母 (
_T) 的名称和包含两个连续下划线的名称保留供实现使用。不要在你的代码中使用它们。
标签: c++ class templates typedef