我有一个抽象基类,它需要一些对象传递给它的构造函数来初始化它的成员。但我想摆脱通过派生类构造函数传递这些对象。
class Derived : public Base
{
public:
Derived(type one, type two, type three) : Base(one, two, three)
{
// ...
传递给基类的对象对于所有创建的派生类都是相同的实例。有没有办法将它们绑定到基类的构造函数,这样我就不必通过派生类的构造函数转发它们?
// do some magic
// ...
class Derived : public Base
{
// no need for an explicit constructor anymore
// ...