Topic: scope and extent of c++ temporary object


Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Wed, 2 Mar 1994 15:11:50 GMT
Raw View
kanze@us-es.sel.de (James Kanze) writes:

>|> > >  Tree t1, t2;
>|> > >  Tree *t = &(meld(t1)*meld(t2));
>
>Actually, in the ARM and in the current version of the working papers,
>the expression in question is illegal, since the results of
>multiplication (even user provided multiplication) is not an lvalue,
>and the (built-in) address of operator requires an lvalue.  If your
>compiler accepts this code, then complain to your vendor.

Well, it depends on the definition of operator*() for Trees.
If that operator returns a reference, then the expression _is_ legal.
It is not true that the result of a multiplication expression
is never an lvalue; the ARM explains clearly at the start of chapter 5
that the rules in that chapter only apply to non-overloaded operators,
and that for overloaded operators the rules for function calls
are used instead.

--
Fergus Henderson - fjh@munta.cs.mu.oz.au