我有会员功能:
void ClassA::Method(ClassB& inputarg);
我希望有boost :: function:
boost::function< void (ClassB&) >
FunctionPointer(
boost::bind((&ClassA::Method, _1, _2)(ClassC->ClassA_User, boost::ref(SomeStructure.ClassB_User)));
但它没有编译,我做错了什么?
错误C2064:术语不评估为采用2个参数的函数 错误C2780:'boost :: _ bi :: bind_t&lt; _bi :: dm_result :: type,boost :: _ mfi :: dm,_bi :: list_av_1 :: type&gt; boost :: bind(M T :: *,A1)':需要2个参数 - 提供1个 7个c:\ git \ 3rdparty \ common \ include \ boost \ bind \ bind.hpp(1728):查看'boost :: bind'的声明 错误C2780:'boost :: _ bi :: bind_t,_bi :: list_av_9 :: type&gt; boost :: bind(boost :: type,R(__thiscall T :: *)(B1,B2,B3,B4,B5,B6,B7,B8)const,A1,A2,A3,A4,A5,A6,A7 ,A8,A9)':期望11个参数 - 提供1个 7个c:\ git \ 3rdparty \ common \ include \ boost \ bind \ bind_mf2_cc.hpp(223):参见'boost :: bind'的声明
和更多类似于最后一行的输出。
答案 0 :(得分:1)
如果您想创建boost::function<void(B&)>
,请使用
FunctionPointer(boost::bind(&ClassA::Method, ClassC->ClassA_User, _1));
称之为FunctionPointer(SomeStructure.ClassB_User);
如果要传递B
的绑定已知实例,则FunctionPointer
的类型应为
boost::function<void()>
和bind应该是这样的
boost::bind(&ClassA::Method, ClassC->ClassA_User,
boost::ref(SomeStructure.ClassB_User)));
然后称之为
FunctionPointer()
;