我有如下代码,在派生类的虚函数中,如何调用基类中的同一个函数来修改基类?
class Base{
public:
int a;
virtual Base & operator +=(Base const & rhs)
{
a += rhs.a;
return *this;
}
};
class Derived: public Base{
public:
int b;
virtual Derived & operator +=(Derived const & rhs)
{
// What should I write to invoke the += in Base class?
// something like Base::+=(rhs.Base);
b += rhs.b;
return *this;
}
};
最佳答案
您可以添加:
Base::operator+=(rhs);
调用基本版本。
关于c++ - 修改虚函数中的基类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42616467/