home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1175 < prev    next >
Encoding:
Text File  |  1992-09-14  |  1.9 KB  |  52 lines

  1. Newsgroups: comp.std.c++
  2. Path: sparky!uunet!mcsun!news.funet.fi!network.jyu.fi!sakkinen
  3. From: sakkinen@jyu.fi (Markku Sakkinen)
  4. Subject: Re: Answers on a postcard
  5. Message-ID: <1992Sep14.083425.2938@jyu.fi>
  6. Organization: University of Jyvaskyla, Finland
  7. References: <92255.154216KKEYTE@ESOC.BITNET> <BuH6sK.54r@world.std.com>
  8. Date: Mon, 14 Sep 1992 08:34:25 GMT
  9. Lines: 41
  10.  
  11. In article <BuH6sK.54r@world.std.com> tob@world.std.com (Tom O Breton) writes:
  12. >Karl:
  13. >
  14. >> If not, I would ask: How does one overload the comma operator while
  15. >> maintaining its attibutes as an operator?
  16. >
  17. >
  18. >It's of dubious usefulness but it can be done:
  19. >
  20. >class thisclass
  21. >{ int&  operator,(int a); }
  22. >
  23. >//To call this:  (thisclass)X, (int)Y ... (outside of arg-lists, of course)
  24. >  
  25. >This will return you an int, just as if the default comma operator had
  26. >executed.
  27. > ...
  28.  
  29. Sorry, but you did not see what the problem is.
  30. With an overloaded comma operator it is impossible to make sure
  31. that the first operand (X) is _evaluated_ (completely) before
  32. the second one, as is the case with the built-in operator.
  33. Indeed, one would probably often like not to have the second operator
  34. evaluated yet at all before the operator function is invoked.
  35. This is important if either of the operands is an expression
  36. with side effects (and with the built-in comma, you would not use
  37. it at all unless the first operand really has side effects).
  38.  
  39. BTW, I regard it as a mistake to make comma (and '&') overloadable at all.
  40. It is a clear breach of the principle: "C++ was designed to be
  41. extensible, but not mutable".
  42.  
  43. ----------------------------------------------------------------------
  44. Markku Sakkinen (sakkinen@jytko.jyu.fi)
  45.        SAKKINEN@FINJYU.bitnet (alternative network address)
  46. Department of Computer Science and Information Systems
  47. University of Jyvaskyla (a's with umlauts)
  48. PL 35
  49. SF-40351 Jyvaskyla (umlauts again)
  50. Finland
  51. ----------------------------------------------------------------------
  52.