如何将一个类成员函数与param作为rvalue绑定到boost :: function? [关闭]

问题描述 投票:-1回答:1

我尝试将一个类成员函数与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) 
    }   
};
c++ c++11 boost rvalue-reference rvalue
1个回答
1
投票

使用lambda表达式:

boost::function<int(int&&)> fc = [this](int&& x)
{
    return Foo1(x);
};
© www.soinside.com 2019 - 2024. All rights reserved.