Учитывая следующую функцию, будет ли объявлена каждая из локальных переменных в стеке?
std::string reallyCoolFunction(unsigned int a)
{
if( a < 20 )
{
std::string result1 = "This function is really cool";
return result1;
}
if( a >=20 && a <= 40 )
{
std::string result2 = "This function is kind of cool";
return result2;
}
if( a > 40 )
{
std::string result3 = "This function is moderately cool";
return result3;
}
std::string result4 = "This function really isn't that cool";
return result4; // remove warning
}
В этой ситуации требуется только один std::string
, все ли 4 выделяются в стеке или выделяются только 1?