I was reviewing the code of a junior colleague and encountered the following code.
void ActionGetId(boost::property_tree::ptree& callInfo);
void ActionPutId(boost::property_tree::ptree& callInfo);
void handler(int type, std::string data)
{
boost::property_tree::ptree callInfo(data);
if(type == 0)
{
_ioService.post(boost::bind(&ActionGetId, callInfo);
}
else
{
_ioService.post(boost::bind(&ActionPutId, callInfo);
}
}
They are passing a local variable by reference and then exit the function. When those functions are finally called, the local variable may not exist. Yet, this program doesn't crash. How is this working?
Aucun commentaire:
Enregistrer un commentaire