home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16393 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.4 KB  |  38 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!uwm.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!meibm31.cen.uiuc.edu!pl2440
  3. From: pl2440@meibm31.cen.uiuc.edu (Paul Jay Lucas)
  4. Subject: Re: operator overloading
  5. References: <1992Nov16.200145.23491@aifh.ed.ac.uk>
  6. Message-ID: <Bxu3DB.F7n@news.cso.uiuc.edu>
  7. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  8. Organization: University of Illinois at Urbana
  9. Date: Tue, 17 Nov 1992 00:15:09 GMT
  10. Lines: 26
  11.  
  12. In <1992Nov16.200145.23491@aifh.ed.ac.uk> iab@cstr.ed.ac.uk writes:
  13.  
  14.  
  15. >I'm looking for some help with operator overloading. I have
  16. >successfully overloaded operators acting on statically declared  user
  17. >defined classes but I would like to declare my classes dynamically and
  18. >still use my overloaded operators. Is this possible, i.e. to use
  19. >overloaded operators on pointers to a class without dereferencing
  20. >explicitly.     
  21.  
  22. *****>    No; pointers are not first-class objects; operators can only be
  23.     overloaded for class types.  This shouldn't work any more than:
  24.  
  25.         int i = 1, j = 2, *p = &i, *q = *j;
  26.  
  27.         if ( p == q )    // pointer comparison only!
  28.             // ...
  29.     
  30.     should, i.e., pointers to class types shouldn't get any special
  31.     treatment over pointers to built-in types.
  32.  
  33.     You might consider using references whereever you can.
  34. -- 
  35.     - Paul J. Lucas                University of Illinois    
  36.       AT&T Bell Laboratories        at Urbana-Champaign
  37.       Naperville, IL            pjl@cs.uiuc.edu
  38.