【发布时间】:2013-08-20 12:35:55
【问题描述】:
我有一个抽象基类,它需要一些对象传递给它的构造函数来初始化它的成员。但我想摆脱通过派生类构造函数传递这些对象。
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
// ...
【问题讨论】:
-
您确定
std::bind与此有关吗? -
std::bind允许将值绑定到函数参数。我正在为基类的类构造函数寻找类似的东西。
标签: c++ inheritance constructor stdbind