Created
April 26, 2014 17:36
-
-
Save DieHertz/11326183 to your computer and use it in GitHub Desktop.
Lifetime of temporary object is extended until the end of scope of reference to subobject.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
struct Foo { | |
~Foo() { std::cout << "~Foo()\n"; } | |
}; | |
struct Bar { | |
Foo foo; | |
~Bar() { std::cout << "~Bar()\n"; } | |
}; | |
int main() { | |
auto&& foo = Bar{}.foo; | |
std::cout << "exit\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this particular case, the lifetime of temporary Bar{} is prolonged until the scope of foo ends.