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
You need to make getMessage non-static or you need to make pub static.
Probably what you really need to do is rethink your design. Why are you trying to make getMessage static? As a very general rule of thumb static is a mistake, especially for a newbie.