I'm getting an unexpected behavior when passing a const string
to a function as a parameter.
I have this function:
std::string getStatusByTopic(const std::string topic){
if (topic.compare(TOPIC_WP_SM_CMD) == 0)
return state_to_string(STATUSES::WP_HANDLER_STATUS);
}
Which is not totally implemented yet.
And I have this function:
InsertStatus(getStatusByTopic(TOPIC_WP_SM_CMD),msg);
Which declared as:
void Msp::InsertStatus(const std::string status_topic, const std_msgs::String::ConstPtr& new_status)
I have 2 questions:
These functions have been compiled successfully, even though there's a possible usage where
getStatusByTopic()
returns nothing when its defined returned type is string. How is it possible?When the code is executed, with the scenario that and
getStatusByTopic(TOPIC_WP_SM_CMD)
returns nothing. There's no runtime errors, more over - TOPIC_WP_SM_CMD is passed as parameter toInsertStatus()
(which is defined ad "/some/topic/"). How is that possible?
Thanks.