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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!umn.edu!csus.edu!borland.com!pete
  3. From: pete@borland.com (Pete Becker)
  4. Subject: Re: Complex Addition.
  5. Message-ID: <1992Dec11.232954.7071@borland.com>
  6. Originator: pete@genghis.borland.com
  7. Sender: news@borland.com (News Admin)
  8. Organization: Borland International
  9. References: <1992Dec11.170849.18525@rs6000.bham.ac.uk>
  10. Date: Fri, 11 Dec 1992 23:29:54 GMT
  11. Lines: 48
  12.  
  13. In article <1992Dec11.170849.18525@rs6000.bham.ac.uk> pickerig@eee.bham.ac.uk (Guy Pickering) writes:
  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? Doesn't the complex object go out of scope?
  23. >
  24.  
  25.     Yes, it does.  But that's not the end of the inquiry.
  26.  
  27.     int add( int a, int b )
  28.     {
  29.     return a+b;
  30.     }
  31.  
  32.     Here, too, the temporary goes out of scope, but the compiler knows how
  33. to deal with that.  Same thing for an object of a user-defined type.
  34.  
  35. >Could I do this:
  36. >
  37. >SomeClass operator<<(SomeClass data, int places)
  38. >{
  39. >  SomeClass temp(data);        // Copy data to temporary object.
  40. >
  41. >  // manipulate temp internally to perform
  42. >  // the << operation.
  43. >
  44. >  return temp;
  45. >}
  46. >
  47. >Would this allow me to write:
  48. >
  49. >  value1 = value2 << 5;
  50. >
  51. >If both variables were of type SomeClass?
  52. >
  53.  
  54.     Yes.
  55.  
  56.     -- Pete
  57.  
  58.  
  59.  
  60.  
  61.