0

I have a Base class and a "child" class named Something which uses private inheritance for reusing generated code.

class Base {
protected:
    Base();
public:
    virtual ~Base(){}
    void cool();
    Base& operator=(const Base& other);
};
class Something : private Base {       
public:
     Something();
     void cool(){
           // own stuff
           // call method from base
           Base::cool();
           // own stuff
     } 

     Something& operator=(const Something& other){
           if (this != &other){
              // do own things

And now here, between decoration, should be the call of the operator= from base class. But I am not sure how I should do this in right way. Should I use dynamic_cast something like this:

              (dynamic_cast<Base>(*this)).operator =(dynamic_cast<Base>(other));
              // do own things
           }
           return *this;
     }

}

Best regards.

ifrh
  • 29
  • 5

1 Answers1

2

Despite using private inheritance, Something is still a Base, so it is allowed to directly call the Base's operator =() with the passed-in Something.

So: Base::operator =(other);

John Burger
  • 3,662
  • 1
  • 13
  • 23