I know this question had been asked many times but I'm still stuck. I thought I got what this error was about what obviously I don't.
So, the error I am getting is
a nonstatic member reference must be relative to a specific object
My code is:
class theTranslator {
public:
ros::NodeHandle nh;
ros::Publisher pub = nh.advertise<sensor_msgs::Image>("camera/depth/image_raw", 100);
static void getMessage(const sensor_msgs::Image::ConstPtr& recMmsg) {
ROS_INFO( "I heard message" );
pub.publish(recMmsg); //*** ERROR IS HERE ***
}
};
since pub
is part of the same class as getMessage()
, shouldn't it work? How can I make a static
member function use a variable member of the same class?
P.S. this is done in ROS (Robotics Operating System) but I believe this is a C++ mistake (not related to ROS).