我在理解这些代码行的某些部分时遇到麻烦:
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)
谢谢
boost::bind
为您提供了一个函数,该函数映射其参数以调用另一个函数,然后可选地添加它已经知道的一些函数。它现在是标准的一部分,因此您可以在cppreference中阅读更多内容。
boost::bind
用于bind函数的某些参数。结果是一个带有较少参数的函数。
您函数中的代码行基本上等同于:
fn = [this, &world](auto arg1, auto arg2, auto arg3) {
return checkFeasibility(&world, arg1, arg2, arg3);
}
bind
的参数是您要调用的函数以及该函数的所有参数。您可以将它们设置为固定值,也可以使用占位符_1
,_2
等暂时保留它们,并在调用结果函数时传递它们。对于成员函数,其隐式第一个参数是this
指针,因此,在这种情况下,要绑定的第二个参数是调用该函数的对象。