declaring publisher outside main ros c++ code example
Example: roscpp publish int32
#include <std_msgs/Int8.h>
std_msgs::Int8 msg;
msg.data = 17;
ROS_INFO("%d", msg.data);
chatter_pub.publish(msg);
#include <std_msgs/Int8.h>
std_msgs::Int8 msg;
msg.data = 17;
ROS_INFO("%d", msg.data);
chatter_pub.publish(msg);