ros中关于回调函数的问题
关于msg类型的问题
const Msg::ConstPtr& VS const Msg& (待解决)
使用 const Msg::ConstPtr& 或者const Msg可以把msg信息输出来
void Callback(const common_msgs::objects msg){
std::cout<< "objects:\n" << msg <<std::endl;
}
void Callback(const common_msgs::objects::ConstPtr& msg){
std::cout<< "objects:\n" << *msg <<std::endl;
}
但是使用const Msg& 就会报错,
void obstacleCallback(const common_msgs::objects& msg){
std::cout<< "objects:\n" << msg <<std::endl;
错误是:
/usr/include/boost/function/function_template.hpp:117:11: error: invalid initialization of reference of type ‘const common_msgs::Perceptionobjects_<std::allocator<void> >&’ from expression of type ‘const boost::shared_ptr<const common_msgs::Perceptionobjects_<std::allocator<void> > >’
117 | BOOST_FUNCTION_RETURN(f(BOOST_FUNCTION_ARGS));