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
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…