home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17819 < prev    next >
Encoding:
Text File  |  1992-12-11  |  1.5 KB  |  56 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!ornl!utkcs2!emory!swrinde!sdd.hp.com!ux1.cso.uiuc.edu!cs.uiuc.edu!sparc0b!pjl
  3. From: pjl@cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: Complex Addition.
  5. Message-ID: <Bz3ynn.A1w@cs.uiuc.edu>
  6. Sender: news@cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <1992Dec11.170849.18525@rs6000.bham.ac.uk>
  9. Date: Fri, 11 Dec 1992 18:42:59 GMT
  10. Lines: 44
  11.  
  12. In <1992Dec11.170849.18525@rs6000.bham.ac.uk> pickerig@eee.bham.ac.uk (Guy Pickering) writes:
  13.  
  14. >In ARM, the code for the `+` operator for the complex class is given as:
  15.  
  16. >inline complex operator+(complex a, complex b)
  17. >{
  18. >  return complex(a.re+b.re,a.im+b.im)
  19. >}
  20.  
  21. >In general, can I create an instance of a class in a member function and
  22. >return the object?
  23.  
  24. *****>    Yes.
  25.  
  26. >Doesn't the complex object go out of scope?
  27.  
  28. *****>    It's not in the scope of the function; it's in a temporary for
  29.     the return-value of the function that gets destroyed sometime
  30.     thereafter.
  31.  
  32. >Could I do this:
  33.  
  34. >SomeClass operator<<(SomeClass data, int places)
  35. >{
  36. >  SomeClass temp(data);        // Copy data to temporary object.
  37.  
  38. >  // manipulate temp internally to perform
  39. >  // the << operation.
  40.  
  41. >  return temp;
  42. >}
  43.  
  44. >Would this allow me to write:
  45.  
  46. >  value1 = value2 << 5;
  47.  
  48. >If both variables were of type SomeClass?
  49.  
  50. *****>    Yes, but you don't need 'temp' since 'data' is a copy anyway
  51.     since you aren't passing it by reference.
  52. -- 
  53.     - Paul J. Lucas                University of Illinois    
  54.       AT&T Bell Laboratories        at Urbana-Champaign
  55.       Naperville, IL            pjl@cs.uiuc.edu
  56.