Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Callback with "this"

I'm trying to call a callback function with a "this" pointer in the following way:

ros::Subscriber sub = node.subscribe("map_metadata", 1, &Obstacle::metaDataCallback, this);

The Callback function is:

//Get the occupancy grid metadata.
void Obstacle::metaDataCallback(const nav_msgs::MapMetaData::ConstPtr& msg) {       
        this->width = msg->width;
        this->height = msg->height;
        this->resolution = msg->resolution;
}

When I try to print the width, height and resolution of "this" after the callback has returned, the values are always 0 (as when initialized). However, I know they should be 288, 288 and 0.1 respectively. Why aren't the parameters properly stored in "this"? How can I make it so?