Getting error “a nonstatic member reference must be relative to a specific object” while both member are in the same class

In C++ you can not access a non static class member from a static method. Make it a normal method and try like below:-

 void getMessage(const sensor_msgs::Image::ConstPtr& recMmsg){
        ROS_INFO( "I heard message" );
        pub.publish(recMmsg); //*** ERROR IS HERE ***
    }

Else declare pub as static member

static ros::Publisher pub; 

Also refer to the below answer

C++ static member functions and variables

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)