简体   繁体   中英

Boost:bind and Boost::function

Im trying to use my member function as a boost function , but it does not work.

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:

#include <boost/bind/placeholders.hpp>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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