I have a class B
with a set of constructors and an assignment operator.
Here it is:
class B
{
public:
B();
B(const string& s);
B(const B& b) { (*this) = b; }
B& operator=(const B & b);
private:
virtual void foo();
// and other private member variables and functions
};
I want to create an inheriting class D
that will just override the function foo()
, and no other change is required.
But, I want D
to have the same set of constructors, including copy constructor and assignment operator as B
:
D(const D& d) { (*this) = d; }
D& operator=(const D& d);
Do I have to rewrite all of them in D
, or is there a way to use B
's constructors and operator? I would especially want to avoid rewriting the assignment operator because it has to access all of B
's private member variables.
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…