c++ - Does the temporary B() have its lifetime extended by the initialization of the reference int& ri below? -
c++ - Does the temporary B() have its lifetime extended by the initialization of the reference int& ri below? -
this illustration taken §8.5.3/5 (first bullet point) in c++11 standard:
struct { }; struct b : { operator int&(); } b; int& ri = b();
if does, there way access temporary b()
, in code below?
#include <iostream> struct { }; struct b : { int i; b(): i(10) {} operator int&() { homecoming i; } } b; int main() { int& ri = b(); std::cout << ri << '\n'; }
no, destructor temporary b object runs @ end of total expression, usual. not bound reference.
in sec example, ri
reference int
object lifetime has ended.
c++ c++11 reference
Comments
Post a Comment