简体   繁体   English

Boost:bind和Boost :: function

[英]Boost:bind and Boost::function

Im trying to use my member function as a boost function , but it does not work. 我试图使用我的成员函数作为boost函数,但是它不起作用。

I guess the following error message : 我猜下面的错误信息:

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

then I have a popup message saying that I must click ok and this message : 然后我有一个弹出消息,说我必须单击“确定”,然后显示以下消息:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(341,5): error MSB6006: "CL.exe" exited with code 1.

This is my code : 这是我的代码:

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;
}

You have to add a placeholder to bind() call: 您必须添加一个占位符以进行bind()调用:

#include <boost/bind/placeholders.hpp>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM