首页 > 解决方案 > how can I bind a class member function with param as rvalue to boost::function?

问题描述

I try to bind a class member function with param as rval to boost::function. But it doesn't work. my sample false code :

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

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

标签: c++c++11boostrvalue-referencervalue

解决方案


使用 lambda 表达式:

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

推荐阅读