64,682
社区成员
发帖
与我相关
我的任务
分享
typedef int(*PTR)(Callback_MsgInfo*);
boost::function<int(Callback_MsgInfo*)> f = boost::bind(&AAA::callback, this , _1);
PTR* pCallback1 = f.target<PTR>();
boost::_bi::bind_t<int,boost::_mfi::mf1<int,AAA,Callback_MsgInfo *>,boost::_bi::list2<boost::_bi::value<AAA *>,boost::arg<1> > >
而不是 boost::function<int(Callback_MsgInfo*)>[/quote]
类型不对,编译能通过吗?[/quote]
当然可以了 boost::function 的功能就是如此,不管是啥类型的类对象只要有 int operator()((Callback_MsgInfo* ); 这个成员,就可以赋值给 boost::function<int(Callback_MsgInfo*)>
struct Callback_MsgInfo{};
class AAA
{
public:
int callback(Callback_MsgInfo*){ return 0;}
void func()
{
typedef int(*PTR)(Callback_MsgInfo*);
boost::function<int(Callback_MsgInfo*)> f = boost::bind(&AAA::callback, this , _1);
typedef boost::_bi::bind_t<int,boost::_mfi::mf1<int,AAA,Callback_MsgInfo *>,boost::_bi::list2<boost::_bi::value<AAA *>,boost::arg<1> > > FuncType;
FuncType* v = f.target<FuncType>();
}
};
int main()
{
AAA a;
a.func();
return 0;
}
boost::_bi::bind_t<int,boost::_mfi::mf1<int,AAA,Callback_MsgInfo *>,boost::_bi::list2<boost::_bi::value<AAA *>,boost::arg<1> > >
而不是 boost::function<int(Callback_MsgInfo*)>[/quote]
类型不对,编译能通过吗?boost::_bi::bind_t<int,boost::_mfi::mf1<int,AAA,Callback_MsgInfo *>,boost::_bi::list2<boost::_bi::value<AAA *>,boost::arg<1> > >
而不是 boost::function<int(Callback_MsgInfo*)>