Friday, July 26, 2019

private inheritance in C++ and How to reuse but decorate an operator of base class?

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(*this)).operator =(dynamic_cast(other));
// do own things

}
return *this;
}

}


Best regards.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...