修改虚函数中的基类

时间:2017-03-06 02:10:14

标签: c++ c++11

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

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

1 个答案:

答案 0 :(得分:4)

您可以添加:

Base::operator+=(rhs);

调用基本版本。