【问题标题】:storing the output of boost::bind in a boost::function将 boost::bind 的输出存储在 boost::function 中
【发布时间】:2013-10-25 18:51:46
【问题描述】:

我目前有这样的东西

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

我想调用函数 ptr 但方法没有被调用?关于我可能做错的任何建议?

【问题讨论】:

    标签: c++ boost-bind boost-function


    【解决方案1】:

    它必须是boost::function&lt;void()&gt;,因为没有剩余的参数。

    然后像函数一样调用它:

    parfunct();
    

    【讨论】:

    • 在这种情况下我得到错误error C2064: term does not evaluate to a function taking 0 arguments
    • @Rajeshwar:抱歉,已修复。 bind 中的无关参数被忽略,细微的错误... function 类型必须是您调用,而不是bind 的输入。
    猜你喜欢
    • 2016-03-16
    • 1970-01-01
    • 1970-01-01
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-06
    • 1970-01-01
    相关资源
    最近更新 更多