繁体   English   中英

绑定具有比所需更多的参数的函数,并将确定的参数传递给该函数

[英]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将传递给我的对象。

我该如何使用usind boost:bind?

我想是这样的

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传递到需要可调用的任何上下文,但是它不能转换为函数指针。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM