Boost绑定返回类型差异
Boost bind return type difference
我已经看过关于boost::bind的返回类型是什么?看,简短的答案是你不需要知道。
虽然我有一个以"bind(…)result"为参数的函数,但我发现以下差异行为
工作案例1
void func(int a){};
myfunc(bind(&obj::func,this,_1));
不适用情况2(当我想用2个参数绑定func2时)
void func2(int a, int b){};
myfunc(bind(&obj::func2,this,_1,_2));
用case 3
void func3(int a, int b){};
myfunc(bind(&obj::func3,this,_1, 10));
所以我的问题是下面3的返回类型有什么不同?
bind(&obj::func,this,_1));
bind(&obj::func2,this,_1,10)); //why this one can be passed the same type as above one?
bind(&obj::func3,this,_1,_2));
由于myfunc
是相当嵌入在模板和重载函数中,我还没有找到它是如何定义的,以"bind(…)"作为参数。这就是为什么我没有附加myfunc
正如您链接的答案所示,您实际上不需要知道确切的返回类型。然而,该类型与boost::function
兼容,因此您可以这样做(作为void(void)
的最简单示例):
typedef boost::function<void(void)> myFunctionType;
// this is the function that you want to bind
void foo(){}
// this is the function that should take it as an argument
void myOtherFunction(myFunctionType f);
<...>
// this is how you bind it
myFunctionType bar = boost::bind(foo);
// and this is how you pass it as argument
myOtherFunction(bar);
相关文章:
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 运行时错误:引用绑定到类型为"int"的空指针
- 了解C++如何返回引用并绑定到引用
- 无法将运行时类绑定到 XAML T 必须是 WinRT 类型
- 为什么结构化绑定不使用"auto&"返回对结构成员的引用,而是返回成员本身
- 创建一个函数的 Python 绑定,返回指向带有 boost 的向量的指针
- 运行时错误:引用绑定到类型"int"的未对齐地址0xbebebebebebebec6,这需要 4 个字节对齐 (stl_vector.h)
- 无法将类型"T&"的非常量左值引用绑定到类型"T"的右值 t++ std::atomic<T>
- 结构化绑定初始值设定项表单 { 赋值表达式 } 对于 clang 上的数组类型失败
- 在其他容器中使用 boost::container::static_vector 时,GCC 编译错误"将'const s'绑定到类型's&'的引用丢弃限定符"
- std::绑定variadic模板和自动返回类型
- C++ 如何将参数绑定到具有相同返回类型的函数,并将它们全部存储在一个容器中
- 助推.绑定返回类型
- 通过将返回值绑定到const引用,C++性能得到改善
- 类型绑定引用中的限定符和 const 类型的初始值设定项中删除
- 提升 Python:使用 return_internal_reference 将参数的生存期与返回值绑定
- C++绑定返回类型模板参数
- Boost绑定返回类型差异
- 关于模板类的未绑定模板友元函数的返回类型
- 为什么我不能让 std::function<std::vector<T>::iterator> 绑定到返回该类型的 lambda?