KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have code that looks like this: class T {}; class container { const T &first, T &second; container(const T&first, const T & second); }; class adapter : T {}; container(adapter(), adapter()); I thought lifetime of constant reference would be lifetime of container. However, it appears otherwise, adapter object is destroyed after container is created, leaving dangling reference. What is the correct lifetime? is stack scope of adapter temporary object the scope of container object or of container constructor? how to correctly implement binding temporary object to class member reference? Thanks
Tags (comma-separated)
Save Edits
Cancel