我有以下代码,在派生类的虚函数中,如何在基类中调用相同的函数来修改基类?
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;
}
};
答案 0 :(得分:4)
您可以添加:
Base::operator+=(rhs);
调用基本版本。