c++ - 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)
}
};
解决方案
使用 lambda 表达式:
boost::function<int(int&&)> fc = [this](int&& x)
{
return Foo1(x);
};
推荐阅读
- c - 当“aa”字符串分配给整数变量时发生了什么?
- unity3d - 无法加载文件或程序集“Facebook.Unity.Canvas”
- java - 以编程方式单击工具栏中的后退箭头
- ghostscript - GhostScript和Xpdf在将pdf转换为png上有什么区别
- javascript - 谷歌登录api(platform.js)设置没有SameSite属性的cookie?
- android - 无线运行/安装/调试 android 应用程序,但通过其自己的便携式热点
- .net-core - WSO2 API 管理器与微型网关
- jquery - 使用 JQuery 对选择选项进行排序
- r - 为什么当我使用 rep() 时 rbind 不起作用?
- javascript - Angular:展平/取消展平嵌套的 JSON 对象