是否有可能从boost :: function继承?

sbr*_*ett 4 c++ inheritance boost

我想知道是否可以继承boost :: function.

基本上,为了便于使用,我想要的是一个类型"Delegate",它基本上是一个boost :: function.它只是为了易于使用我正在编写的一些代码.

我曾经将typedef的boost :: function转移到Delegate,但在我的经验中,typedef'ing与gdb的东西一起玩.特别是如果它是模板化的,那么我想避免这种情况(曾经尝试调试已经装入的stl容器?oofta).

我在网上找到了一些代码,给出了一些例子:

template<class Signature>
class Delegate : public boost::function<Signature>
{
public: 
    using boost::function<Signature>::operator();
};
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试使用它时,我遇到了一些错误.一个用法示例是:

Tank * tankptr = new Tank();
Delegate<void ()> tankShoot(boost::bind(boost::mem_fn(&Tank::Shoot),tankptr));
Run Code Online (Sandbox Code Playgroud)

这会产生诸如此类的错误

error: no matching function for call to ‘Delegate<void ()()>::Delegate(boost::_bi::bind_t<boost::_bi::unspecified, boost::_mfi::mf0<void, Tank>, boost::_bi::list1<boost::_bi::value<Tank*> > >)’
Delegate.h:26: note: candidates are: Delegate<void ()()>::Delegate()
Delegate.h:26: note:                 Delegate<void ()()>::Delegate(const Delegate<void()()>&)
Run Code Online (Sandbox Code Playgroud)

如果我不得不猜测为什么我会收到这些错误,我不得不说这是因为我缺少某种复制构造函数,它接受boost :: bind构造函数返回的任何基础.

关于如何克服这个障碍的任何想法,或者任何能够指出我继承boost :: function的好例子的人?

hka*_*ser 6

派生类不会自动"继承"派生类的基类构造函数.您需要在那里创建所有必需的构造函数.