After reading this answer from ildjarn , I wrote the following example, and it looks like an unnamed temporary object has the same lifetime as its link!
- How is this possible?
- Is it specified in the C ++ standard?
- Which version?
Source:
#include <iostream> //cout
Execution:
> g++ --version g++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-54) Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. > g++ main.cpp -O3 > ./a.out Beginning Next should be '1234': 1234
c ++ reference temporary object-lifetime
oliber
source share