Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Look up "variable scope in C++" to understand how variables like ros::Publisher pub can be declared and used in C++ programs.

The preferred method is to create a class like class MyNode, and declare ros::Publisher pub; as a private variable in the class. But if you just want to quickly hack up existing C++ code you can just declare ros::Publisher pub; as a global variable somewhere near the top of the cpp file, and use it later.