如何将带有param作为rvalue的类成员函数绑定到boost :: function?

时间:2018-08-03 08:53:53

标签: c++ c++11 boost rvalue-reference rvalue

我尝试将带有param的类成员函数作为rval绑定到boost :: function。 但这是行不通的。 我的示例错误代码:

class Class1
{
    int Foo1(int&& b)
    {
        return b;
    }   

    void foo2()
    {
        boost::function<int(int&&)> fc(boost::bind(&Class1::Foo1, this, _1) 
    }   
};

1 个答案:

答案 0 :(得分:1)

使用lambda表达式:

boost::function<int(int&&)> fc = [this](int&& x)
{
    return Foo1(x);
};
相关问题