首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Boost:bind和Boost::function

Boost:bind和Boost::function
EN

Stack Overflow用户
提问于 2015-03-29 23:00:55
回答 1查看 89关注 0票数 0

我试图使用我的成员函数作为一个促进功能,但它不起作用。

我猜以下错误消息:

代码语言:javascript
复制
 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 ...

然后我有一条弹出消息说我必须单击“确定”,这条消息:

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

这是我的密码:

代码语言:javascript
复制
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;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-29 23:21:14

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

代码语言:javascript
复制
#include <boost/bind/placeholders.hpp>

boost::function<double(const std::vector<double> &)> f  =
    boost::bind(&MyClass::MyMemberFunction, this, _1);
//                                               ^^^
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29335985

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档