It's not necessary, this section was just showing how to do it in C++ code if you wanted to. This can be useful for certain topics that are meant to only publish to ROS (visualization markers, for example).