The Lifetime of A Temporary and Its Extension: Explained

1 · Yang Yang · March 4, 2019, midnight
You probably already known that, in C++, every temporary object has a lifetime, which begins when it is created and ends when it is destroyed automatically. However, do you know you can extend temporary objects’ lifetime with a reference? In this post, we are going to discuss the lifetime of temporary objects, how to extend their lifetime with a reference, and also the exceptions when that extension cannot be applied. Sample Code A piece of sample code is worth a thousand words. This post contai...