[c++] does a const reference prolong the life of a temporary or not?
- by Kyle
Why is the output to this
#include <string>
#include <iostream>
using namespace std;
class Sandbox
{
public:
Sandbox(const string& n) : member(n) {}
const string& member;
};
int main()
{
Sandbox sandbox(string("four"));
cout << sandbox.member << endl;
return 0;
}
this
The answer is:
and not
The answer is: four
?