home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / std / cplus / 919 < prev    next >
Encoding:
Text File  |  1992-07-22  |  1.3 KB  |  35 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!microsoft!hexnut!jimad
  3. From: jimad@microsoft.com (Jim Adcock)
  4. Subject: Re: How do I... (regarding overloading)
  5. Message-ID: <1992Jul23.012111.16784@microsoft.com>
  6. Date: 23 Jul 92 01:21:11 GMT
  7. Organization: Microsoft Corporation
  8. References: <1992Jul21.144856.583@ualr.edu> <1992Jul21.232959.13540@sunb10.cs.uiuc.edu>
  9. Distribution: usa
  10. Lines: 23
  11.  
  12. In article <1992Jul21.232959.13540@sunb10.cs.uiuc.edu> pjl@sparc1.cs.uiuc.edu (Paul Lucas) writes:
  13. |*****>    operator= has got nothing to do with it unless the thing that []
  14. |    returns is itself a class object (in which case operator= would
  15. |    be overloaded in _that_ class--whether operator= is overloaded
  16. |    in _this_ class is irrelevant...unless you're doing something
  17. |    non-canonical).  operator[] should return a reference to the
  18. |    thing...that's it; the assignment just happens.  
  19.  
  20. The overloading of operator= becomes relevant IF some committee members
  21. succeed in changing the language such that functions cannot be invoked
  22. on temporaries.  Then the common approach of returning a SmartRef from
  23. operator[] fails:
  24.  
  25. bitarray[100] = TRUE; // code in error if functions cannot
  26.                       // be invoked on temporaries!
  27.  
  28. because this really means:
  29.  
  30. bitarray.operator[](100).operator=(TRUE);
  31.  
  32. where operator[] is returning a temporary SmartBitRef that in turn has
  33. its operator= on it.
  34.  
  35.