dimanche 5 mars 2017

Modify base class in virtual function

I have following code, in the virtual function of the derived class, how can I invoke the same function in the base class to modify the base class?

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

Aucun commentaire:

Enregistrer un commentaire