绑定参数多于所需的函数,并向其传递明确的参数
Binding function with more arguments than needed and passing definite arguments to it
让我有一个函数
void f1(type_a a, type_b b, type_c c)
我想把它转换成
void f2(type_a a, type_b b)
其中将传递我的对象,而不是c。
我如何做到这一点?
我认为是这样的
boost::bind(&f1, _1, _2, c_default_value);
C++不是一种函数式语言,因此不能对函数进行真正的部分应用。您可以做以下操作:
#include <boost/bind.hpp>
void f1(int a, double b, char c)
{}
int main()
{
auto binder = boost::bind(&f1, _1, _2, 'c');
binder(1, 2.0);
}
但是,请注意,虽然您可以将binder
传递到任何需要可调用的上下文,但不能转换为指向函数的指针。
相关文章:
- 变量是否会自动转换为函数所需的类型作为适当的参数
- 不能使用嵌套结构中的联合元素作为 scanf() 的参数来存储所需的值
- 测量将参数传递到函数所需的时间
- AWS登录INVALIDPARAMETEREXCEPTION缺少所需参数SRP_A
- 减少将参数传递给函数所需的字符串流操作的详细程度
- 错误 MSB4044:未为"CheckRuntimeLibrary"任务提供所需参数的值"RuntimeLibrary"
- 如何将唯一指针传递给函数中所需的特定参数
- 使用通用函数指针C++传递方法所需的类型参数
- glDrawArrays的意外行为-参数顺序错误会产生所需的图像
- 如何为模板类参数指定所需的继承
- 是否有方法为模板参数指定所需的定义
- 构造函数使用多个参数时所需的显式关键字
- 绑定参数多于所需的函数,并向其传递明确的参数
- 我能够调用一个不带在 c++ 中传递所需参数的方法.怎么来了
- 如何仅为实现模板所需的某些参数编写模板专用化
- 如果一个未使用的函数参数是指向函数的指针,则是其实际参数所需的定义
- 是否正在缩小诊断所需的非类型模板参数中的转换范围
- 初始化类;传递所需类的基类,而不是将所需类作为参数传递
- 缺少模板参数或所需的主表达式
- 如何从函数中获取替代值,该函数通过非常量输出参数提供所需数据,以便为其分配对常量变量的引用