我有一个B包含一组构造函数和赋值运算符的类.
这里是:
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
};
Run Code Online (Sandbox Code Playgroud)
我想创建一个D只覆盖函数的继承类,foo()不需要进行其他更改.
但是,我希望D拥有相同的构造函数集,包括复制构造函数和赋值运算符B:
D(const D& d) { (*this) = d; }
D& operator=(const D& d);
Run Code Online (Sandbox Code Playgroud)
我是否必须重写所有这些D,或者有没有办法使用B的构造函数和运算符?我特别想避免重写赋值运算符,因为它必须访问所有B的私有成员变量.