Can I store the Subscriber object on the heap?
Hi,
I'd like to subscribe to topics dynamically. This is a simplified version of my current solution:
class MyClass {
std::vector<ros::Subscriber> rosSubscriberList;
void doSubscribe() {
ros::Subscriber sub = n.subscribe("chatter", 1000, &whatevercallback);
rosSubscriberList.push_back(sub);
}
}
Which works, but I was just wondering whether if it is safe to do this.
I believe the subscriber object gets copied to the vector, then gets destructed. So for a short time there are two subscribers? Also, when the MyClass object gets destructed, does the subscriber in the list gets destructed too?
I was wondering if it would be better to have a vector of type
std::vector<ros::Subscriber*>
and handle object (subscriber) destruction manually. But then there is a copy in that solution too.
Which one would you suggest?