Confusion between ConstPtr vs Ptr
I have recently switched from Python to C++. I was going through the ROS Subscriber tutorials. I came across this piece of code -
void chatterCallback(const std_msgs::String::ConstPtr& msg)
{
ROS_INFO("I heard: [%s]", msg->data.c_str());
}
I wanted some clarity on ConstPtr
.
As per my understanding, we are passing a reference
to the msg
variable in the chatterCallback
function, where in, the msg
variable itself is a pointer
to a std_msgs::String object
.
Assuming my (aforementioned) understanding is correct, why are we using the keyword ConstPtr
?
Is it because the value of the msg
variable isn't changing (i.e. it is always pointing to the same std_msgs::String object
) or it is because the value of the std_msgs::String
object (to which the msg
variable is pointing to) isn't changing?
I went through this discussion on the forum. But, I am still confused.