ROS中c++程序报错 In instantiation of ‘static ros::ParameterAdapter

当我在终端中编译一个ROS的C++程序,出现以下错误:

In file included from /opt/ros/indigo/include/ros/subscription_callback_helper.h:35:0,

                 from /opt/ros/indigo/include/ros/subscriber.h:33,
                 from /opt/ros/indigo/include/ros/node_handle.h:33,
                 from /opt/ros/indigo/include/ros/ros.h:45,
                 from /home/qingdu/catkin_ws/src/youbot_match/src/youbot_match.cpp:5:
/opt/ros/indigo/include/ros/parameter_adapter.h: In instantiation of ‘static ros::ParameterAdapter<M>::Parameter ros::ParameterAdapter<M>::getParameter(const Event&) [with M = std_msgs::Int32MultiArray_<std::allocator<void> >&; ros::ParameterAdapter<M>::Parameter = std_msgs::Int32MultiArray_<std::allocator<void> >&; ros::ParameterAdapter<M>::Event = ros::MessageEvent<const std_msgs::Int32MultiArray_<std::allocator<void> > >; typename boost::remove_reference<typename boost::remove_const<M>::type>::type = std_msgs::Int32MultiArray_<std::allocator<void> >]’:
/opt/ros/indigo/include/ros/subscription_callback_helper.h:144:54:   required from ‘void ros::SubscriptionCallbackHelperT<P, Enabled>::call(ros::SubscriptionCallbackHelperCallParams&) [with P = std_msgs::Int32MultiArray_<std::allocator<void> >&; Enabled = void]’
/home/qingdu/catkin_ws/src/youbot_match/src/youbot_match.cpp:327:1:   required from here
/opt/ros/indigo/include/ros/parameter_adapter.h:78:30: error: invalid initialization of reference of type ‘ros::ParameterAdapter<std_msgs::Int32MultiArray_<std::allocator<void> >&>::Parameter {aka std_msgs::Int32MultiArray_<std::allocator<void> >&}’ from expression of type ‘const std_msgs::Int32MultiArray_<std::allocator<void> >’
     return *event.getMessage();
                              ^
make[2]: *** [youbot_match/CMakeFiles/youbot_match_node.dir/src/youbot_match.cpp.o] Error 1
make[1]: *** [youbot_match/CMakeFiles/youbot_match_node.dir/all] Error 2

make: *** [all] Error 2

后来经过定位才知道在定义话题订阅subscribe函数中的回调函数时,参数没有加上const 关键字 例子如下:

void firePositionCallBack(const  std_msgs::Int32MultiArray& msg){
   

}  //回调函数


int main(int argc, char **argv) {
    ros::init(argc, argv, "youbot_move");
    ros::NodeHandle n;

    
     ros::Subscriber  fire_position_sub = n.subscribe("fire_detection_all",10,firePositionCallBack);
    

    return 0;
}



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章