คำถามติดแท็ก const-reference

5
สมาชิกชั้นอ้างอิง 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; } ให้ผลลัพธ์จาก: คำตอบคือ: แทน: คำตอบคือ: สี่
โดยการใช้ไซต์ของเรา หมายความว่าคุณได้อ่านและทำความเข้าใจนโยบายคุกกี้และนโยบายความเป็นส่วนตัวของเราแล้ว
Licensed under cc by-sa 3.0 with attribution required.