【问题标题】:how can I bind a class member function with param as rvalue to boost::function? [closed]如何将具有参数的类成员函数作为右值绑定到 boost::function? [关闭]
【发布时间】:2018-08-03 08:53:53
【问题描述】:

我尝试将带有参数的类成员函数作为 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】:

使用 lambda 表达式:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    相关资源
    最近更新 更多