修改虚拟函数中的基类

Modify base class in virtual function

本文关键字:基类 函数 虚拟 修改      更新时间:2023-10-16

我有以下代码,在派生类的虚拟函数中,如何在基类中调用相同的函数以修改基类?

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);

致电基本版本。