我可以在不编写operator =()的情况下调用其基类的赋值运算符吗?

时间:2016-04-02 03:18:04

标签: c++

我有一个模板类。 template参数设置为模板类的基类;请参阅以下代码。我可以在不编写operator =()的情况下调用基类的赋值运算符=()吗?我希望你能得到我想告诉你阅读和比较以下几行的内容,

this->template T_Base::operator=(orig);  // This is ok

this->template T_Base = orig;  // Error

。我想知道写第二个的方法。 非常感谢你。

class Base {
public:
    Base& operator= (const Base& orig) {
        return *this;
    }
    virtual ~Base() {};
};

template <typename T_Base>
class TemplateBase : public T_Base {
public:
    TemplateBase& operator= (const TemplateBase& orig) {
        this->template T_Base::operator=(orig);  // This is ok
        this->template T_Base = orig;  // Error
        return *this;
    }
};

0 个答案:

没有答案
相关问题