Tag: 常量引用

const引用是否延长了临时的生命?

为什么这样做: #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 << "The answer is: " << sandbox.member << endl; return 0; } 给出输出: 答案是: 代替: 答案是:四