home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!microsoft!hexnut!jimad
- From: jimad@microsoft.com (Jim Adcock)
- Subject: Re: Complex Addition.
- Message-ID: <1992Dec14.211941.20150@microsoft.com>
- Date: 14 Dec 92 21:19:41 GMT
- Organization: Microsoft Corporation
- References: <1992Dec11.170849.18525@rs6000.bham.ac.uk> <Bz3ynn.A1w@cs.uiuc.edu>
- Lines: 22
-
- In article <Bz3ynn.A1w@cs.uiuc.edu> pjl@cs.uiuc.edu (Paul Lucas) writes:
- |In <1992Dec11.170849.18525@rs6000.bham.ac.uk> pickerig@eee.bham.ac.uk (Guy Pickering) writes:
- |>inline complex operator+(complex a, complex b)
- |>{
- |> return complex(a.re+b.re,a.im+b.im)
- |>}
- |
- |>Doesn't the complex object go out of scope?
- |
- |*****> It's not in the scope of the function; it's in a temporary for
- | the return-value of the function that gets destroyed sometime
- | thereafter.
-
- Nit disagreement. I'd claim that the return expression must be in
- the scope of the function. In this case the "complex(...)" must
- be the return expression and thus must be in scope of the function.
- Thus "complex(...)" creates an unnamed temporary object that is
- in scope. Its *another* unnamed temporary inited from this unnamed
- temporary "that gets destroyed sometime thereafter." Of course, the
- compiler typically can realize that two unnamed temporaries are
- unnecessary and optimize this down to one unnamed temporary, or mayne
- even zero unnamed temporaries depending on calling context...
-