White Wolf wrote:[color=blue]
>
>
> So assume that o.wrapper() returns a wrapper type T by value. The foo() and
> bar() are member functions of that unnamed temporary of type T, where both
> (at least foo) return a reference to T. The full expression is:
>
> o.wrapper().foo().bar();
>
> Of course it could be continued ad nauseam. I am 99% sure that the
> temporary should live long enough, but... not 101%. :-)[/color]
100% is enough. You are right
[color=blue]
> Could someone help
> me out with the right answer... and - if possible - the chapter and verse?[/color]
Sure.
12.2 Temporary objects
3 .... Temporary objcets are destroyed as the last step in evaluating the full
expression (1.9) that (lexically) contains the point where they were created.
This is true even if that evaluation ends in throwing an exception.
4 There are two contexts in which temporaries are destroyed at a different point
then the end of the fill expression. The first context is when an expression
appears as an initializer for a declarator defining an object. In that context,
the temporary that holds the result of the expression shall persist until the
object's initialization is complete. The object is initialized from a copy of
the temporary; during this copying, an implementation can call the copy constructor
many times; the temporary is destroyed after it has been copied, before or when
the initialization completes. ....
5 The second context is when a reference is bound to a temporary. The temporary to which
the reference is bound or the temporary that is the complete object to a subobject
of which the temporary is bound persists for the lifetime of the reference except
as specified below. ....
( Lots more dealing with exceptions of the above. Basically those exceptions deal
with temporaries bound to a reference in an initializer list, temporaries created
for function argument passing, return values )
--
Karl Heinz Buchegger
kbuchegg@gascad.at