官方文档给出的教程如下:
Input
C++: Up to 9 separate filters, each of which is of the form
void callback(const boost::shared_ptr&).
The number of filters supported is determined by the number of template arguments the class was created with. Python: N separate filters, each of which has signature callback(msg).Output
C++: For message types M0…M8,
void callback(const boost::shared_ptr&, …, const boost::shared_ptr&).
The number of parameters is determined by the number of template arguments the class was created with. Python: callback(msg0… msgN). The number of parameters is determined by the number of template arguments the class was created with.
但按照该教程编写回调函数,编译时一直报错,而且错误又臭又长,找不出问题所在。
起初以为是语法问题,改了多种方式和顺序,到注册回调函数的时候依然报错,报错片段如下
研读了一番示例代码后,发现使用的消息类型为sensor_msgs::Image
,回调函数中参数类型为const sensor_msgs::ImageConstPtr &
进而去查了该类型的文档,发现对比如下
sensor_msgs是一个命名空间,而Image是该命名空间中的一个类。前面的
::
表示全局
于是在回调函数参数前加了::
顺利解决问题