title: Getting error "a nonstatic member reference must be relative to a specific object" while both member are in the same class
body: <p>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.</p>
  
  <p>So, the error I am getting is </p>
  
  <pre><code>a nonstatic member reference must be relative to a specific object
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>class theTranslator {
  public:
      ros::NodeHandle nh;
  
      ros::Publisher pub = nh.advertise&lt;sensor_msgs::Image&gt;("camera/depth/image_raw", 100);
  
      static void getMessage(const sensor_msgs::Image::ConstPtr&amp; recMmsg) {
          ROS_INFO( "I heard message" );
          pub.publish(recMmsg); //*** ERROR IS HERE ***
      }
  };
  </code></pre>
  
  <p>since <code>pub</code> is part of the same class as <code>getMessage()</code>, shouldn't it work? How can I make a <code>static</code> member function use a variable member of the same class?</p>
  
  <p>P.S. this is done in <em>ROS</em> (Robotics Operating System) but I believe this is a C++ mistake (not related to ROS).</p>