I was wondering where a temporary object is stored when calling a function that takes a const reference.
In the scenario below, in the foo function we create a temporary std::string object and pass it as an argument to print_name function. Which takes a const reference. Is it stored somewhere on a heap and than gets destroyed as soon as print_name function goes out of scope?
Thanks
void print_name(const std::string& name)
{
std::cout << name << std::endl;
}
void foo()
{
print_name( std::string("John") );
}