【发布时间】:2017-07-25 17:03:23
【问题描述】:
我们收到此编译错误,随后出现更多错误,显示在使用 boost::bind 作为订阅回调时尝试将订阅参数与所有可能的候选函数匹配。
error: no matching function for call to ‘ros::NodeHandle::subscribe(const char [18], int, boost::_bi::bind_t<void, void (*)(const geometry_msgs::WrenchStamped_<std::allocator<void> >&, moveit::planning_interface::MoveGroup&), boost::_bi::list2<boost::arg<1>, boost::_bi::value<moveit::planning_interface::MoveGroup*> > >)’
我们的代码如下。注释行显示了在未传递 MoveGroup 上下文(对象指针)时工作的代码。
#include <stdio.h>
#include <boost/bind.hpp>
#include <geometry_msgs/WrenchStamped.h>
#include <moveit/move_group_interface/move_group.h>
using namespace Eigen;
using namespace std;
//void contact_callback(const geometry_msgs::WrenchStamped& msg) {
void contact_callback(const geometry_msgs::WrenchStamped& msg, moveit::planning_interface::MoveGroup &group){
//if(msg.wrench.force.z > 5) group.stop();
}
int main(int argc, char **argv) {
ros::init(argc, argv, "get_stiffness");
ros::NodeHandle node_handle;
ros::AsyncSpinner spinner(1);
spinner.start();
moveit::planning_interface::MoveGroup group("manipulator");
ros::Subscriber contact_sub;
//contact_sub = node_handle.subscribe("/finger1/nano17ft",1,contact_callback);
contact_sub = node_handle.subscribe("/finger1/nano17ft",100,boost::bind(contact_callback,_1,&group));
ros::waitForShutdown();
return 0;
}
【问题讨论】:
-
注意:C++ 标准提供
std::bind已经年了。没有理由使用增强版。 -
@JesperJuhl 存在细微差别(表达式模板,例如否定谓词、绑定到成员函数的智能指针、
boost::protect等) -
@sehe 好点。
标签: c++ boost ros boost-bind moveit