ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

If you don't like global variables, you can also pass the publisher by reference to a function:

void worker (ros::Publisher& pub)
{
  //...
}

int main (int argc, char** argv)
{
  //...
  ros::NodeHandle nh;
  ros::Publisher pub = nh.advertise<PointCloud>("points2", 1);
  //...
  worker(pub);
  //...
}