链接到我的另一个问题(我可以在返回子类类型的基类上创建一个赋值运算符)我有这个构造,我的想法是我想从中派生专门的类型,GPtrBase
而不必每次都重新编写一个赋值运算符:
template<class BaseType,class Self>
class GPtrBase
{
public:
...
Self& operator=(const BaseType& rhs)
{
...
return *this;
}
};
但是,当我专门喜欢:
class GDrawablePtr : public GPtrBase<MyDrawable,GDrawablePtr>
我收到错误:
'return' : 无法从 'GPtrBase<Base,Self>' 转换为 'GDrawablePtr &'
我认为模板类是根据所使用的专业化生成的,所以首先不*this
应该是类型GDrawablePtr
吗?
更新:我注意到如果我添加using GPtrBase::operator=;
它然后工作,即使GDrawablePtr
绝对没有定义任何运算符。