home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!ornl!utkcs2!emory!swrinde!sdd.hp.com!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjl
- From: pjl@cs.uiuc.edu (Paul Lucas)
- Subject: Re: Complex Addition.
- Message-ID: <Bz3ynn.A1w@cs.uiuc.edu>
- Sender: news@cs.uiuc.edu
- Organization: University of Illinois at Urbana-Champaign
- References: <1992Dec11.170849.18525@rs6000.bham.ac.uk>
- Date: Fri, 11 Dec 1992 18:42:59 GMT
- Lines: 44
-
- In <1992Dec11.170849.18525@rs6000.bham.ac.uk> pickerig@eee.bham.ac.uk (Guy Pickering) writes:
-
- >In ARM, the code for the `+` operator for the complex class is given as:
-
- >inline complex operator+(complex a, complex b)
- >{
- > return complex(a.re+b.re,a.im+b.im)
- >}
-
- >In general, can I create an instance of a class in a member function and
- >return the object?
-
- *****> Yes.
-
- >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.
-
- >Could I do this:
-
- >SomeClass operator<<(SomeClass data, int places)
- >{
- > SomeClass temp(data); // Copy data to temporary object.
-
- > // manipulate temp internally to perform
- > // the << operation.
-
- > return temp;
- >}
-
- >Would this allow me to write:
-
- > value1 = value2 << 5;
-
- >If both variables were of type SomeClass?
-
- *****> Yes, but you don't need 'temp' since 'data' is a copy anyway
- since you aren't passing it by reference.
- --
- - Paul J. Lucas University of Illinois
- AT&T Bell Laboratories at Urbana-Champaign
- Naperville, IL pjl@cs.uiuc.edu
-