Hi @Leezy,
I recommend you to start learning some concepts of C++ and, in general, of Object-oriented programming. You have plenty of resources on the Internet to learn about conpects like class, like this or this. Although this is a bit out of the scope of this forum but I will try to answer your questions.
The code you are using contains two chunks of code: the header file .h that declares the class which is going to use the publisher, and the .cpp code that is the actual implementation of the class. To be able to use the class you need a special function that is going to initialize the class to work. In your code, the ExampleTalker
is the class that implements the talker (node with publisher) and the line ExampleTalker::ExampleTalker(nh)
is the line where this function is implemented, that is called a constructor of the class and it is used to initialize all class attributes (including nodehandle and publisher and reading from the parameter server). That is the syntax used in C++ to define a constructor and it is something particular to the class constructor implementation; its name is repeated because the contructor must be inside its actual class (whose name is ExampleTalker
).
However, to answer your second question. When you want to use the class, you have to initialize it by using the constructor already implemented. Since the code is inside a name_space (node_example
) and the constructor name is ExampleTalker
you need to initialize you new class like node_example::ExampleTalker node(nh)
that is: name_space::class:_name(params). Now, with that line you already have you talker object ready to publish new msgs.
Hope that help.
Regards.