ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Answer for Q1:
The return type of a function / method is before the function / method name. In this case it is Subscriber
.
Answer for Q2:
The subscribe
methods return a reference counted publisher. When all copies of it go out of scope it will unsubscribe from the topic. Therefore the subscribers are stored in a vector to prevent them from going out of scope. You could also store each subscriber in a local variable instead. I vector has nothing to do with threads.
Answer for Q3:
I think you need to google a bit about variable scope, reference counting and when such objects are being deleted. A simple example:
{
Subscriber s = node_handle.subscribe<std_msgs::String>(...);
// some more code
} <-- in this line the scope of variable "s" on the stack ends, therefore it is being removed
In case of an object it is being destructed. In case of a reference counted instance it is being destructed if no other reference is stored anywhere.
By storing the subscriber in the vector (which has a bigger scope) the subscriber is not being removed yet but stays around (in the case of the tutorial until the program terminates).