boost :: bind如何在C ++中传递参数?

问题描述 投票:0回答:2

我在理解这些代码行的某些部分时遇到麻烦:

fn_ = boost::bind(&CheckFeasibility, this, &world_, _1, _2, _3 );

if (robot_state_->setFromIK(arg1, arg2, arg3, arg4, arg5, fn_ ))

第一行中this的目的是什么,何时以及如何确定并传递CheckFeasibility的参数?

这里是CheckFeasibility函数的样子(我省略了参数的数据类型):

bool CheckFeasibility(*world, *state, *grp, *values)

谢谢

c++ this ros boost-bind moveit
2个回答
0
投票

boost::bind为您提供了一个函数,该函数映射其参数以调用另一个函数,然后可选地添加它已经知道的一些函数。它现在是标准的一部分,因此您可以在cppreference中阅读更多内容。


0
投票

boost::bind用于bind函数的某些参数。结果是一个带有较少参数的函数。

您函数中的代码行基本上等同于:

fn = [this, &world](auto arg1, auto arg2, auto arg3) {
  return checkFeasibility(&world, arg1, arg2, arg3);
}

bind的参数是您要调用的函数以及该函数的所有参数。您可以将它们设置为固定值,也可以使用占位符_1_2等暂时保留它们,并在调用结果函数时传递它们。对于成员函数,其隐式第一个参数是this指针,因此,在这种情况下,要绑定的第二个参数是调用该函数的对象。

© www.soinside.com 2019 - 2024. All rights reserved.