ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Just a guess, someone that knows the internals can determine this more clearly: This has to do with the fact that a vector inserts by copying values. Before you push_back a temporary is created, which the subscriber is initialized with (including this pointer). This is copied into the vector - the resulting object in the vector has a different this pointer, but the subscriber is copied by value - it can't know the new this pointer. Then the temporary is destroyed and you get random memory when in the callback.

Proper fix for this: Make a copy-constructor + maybe assignment operator that re-initializes the subscriber.