|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-09-04 14:50:50
From: "Thomas Wenisch" <twenisch_at_[hidden]>
> This is incorrect. The code returns a *const* reference to the
> temporary. This extends the life of the temporary to the life of the
> reference.
Yes, but that reference is created within the function. There's another
reference on the outside of the function. By your logic, the temporary
would live forever in this code:
int f();
struct hold { hold(int const& x_) : x(x_) {} int const& x; }
hold* h = new hold(f());
But it doesn't work that way.
-----------------------------------------------------------
David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk