Boost:bind and Boost::function

Boost:bind and Boost::function

本文关键字:Boost function bind and      更新时间:2023-10-16

我试图将我的成员函数用作boost函数,但它不起作用。

我猜以下错误消息:

 warning C4180: qualifier applied to function type has no meaning;   ignored
      ...boostboost_1_55_0boostbindbind_template.hpp(344) : see reference to class template instantiation 'boost::_mfi::dm<double (const std::vector<double,std::allocator<_Ty>> &),MyClass>' being compiled ...

然后我有一条弹出消息,说我必须点击"确定"这个消息:

C:Program Files (x86)MSBuildMicrosoft.Cppv4.0V120Microsoft.CppCommon.targets(341,5): error MSB6006: "CL.exe" exited with code 1.

这是我的代码:

void MyClass::runProcess(){
    boost::function<double(const std::vector<double> &)> f  =
        boost::bind(&MyClass::MyMemberFunction, this);
}
double MyClass::MyMemberFunction(const std::vector<double> & inX){
  return 1.0;
}

您必须向bind()调用添加占位符:

#include <boost/bind/placeholders.hpp>
boost::function<double(const std::vector<double> &)> f  =
    boost::bind(&MyClass::MyMemberFunction, this, _1);
//                                               ^^^