简体   繁体   English

将boost :: bind的输出存储在boost :: function中

[英]storing the output of boost::bind in a boost::function

I currently have something like this 我目前有这样的东西

void asomeMethod(int q)
{
    std::cout << "Method with parameter " << q ;
}

int main()
{
     boost::function<void(int)> parfunct;
     parfunct = boost::bind(&asomeMethod,12);
     parfunct;  //Does not call asomeMethod ??
    return 0;
}

I want to call the function ptr but the method is not being called ? 我想调用函数ptr,但是未调用该方法? Any suggestions on what I might be doing wrong ? 关于我可能做错了什么建议?

It has to be boost::function<void()> , since there's no remaining argument. 它必须是boost::function<void()> ,因为没有剩余的参数。

Then call it like a function: 然后像一个函数一样调用它:

parfunct();

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

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