home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13526 < prev    next >
Encoding:
Text File  |  1992-09-11  |  2.1 KB  |  58 lines

  1. Path: sparky!uunet!news.univie.ac.at!blekul11!frmop11!dearn!esoc!kkeyte
  2. Organisation: European Space Operation Centre (E.S.O.C)
  3. Date: Friday, 11 Sep 1992 11:21:51 CET
  4. From: Karl Keyte <KKEYTE@ESOC.BITNET>
  5. Message-ID: <92255.112151KKEYTE@ESOC.BITNET>
  6. Newsgroups: comp.lang.c++
  7. Subject: Re: Answers on a postcard...
  8. References: <92254.104002KKEYTE@ESOC.BITNET> <1992Sep10.174914.838@taumet.com>
  9. Lines: 47
  10.  
  11. In article <1992Sep10.174914.838@taumet.com>, steve@taumet.com (Steve Clamage)
  12. says:
  13. >
  14. >Karl Keyte <KKEYTE@ESOC.BITNET> writes:
  15. >
  16. >|#include <iostream.h>
  17. >
  18. >|class X {
  19. >|   private:    int           value;
  20. >|   public:     int           operator , (int i) { return i+10; };
  21. >|               int           operator + (int i) { return value+i; };
  22. >|               X &           operator = (int i) { value=i; return *this; };
  23. >|};
  24. >
  25. >
  26. >|void main()
  27. >|{
  28. >|   X         x;
  29. >
  30. >|   cout << "Value is " << (x=1, x+1) << endl;
  31. >|}
  32. >
  33. >In the expression in parens, it is unspecified whether "x=1" or
  34. >"x+1" is evaluated first.  They are arguments to the "operator,()"
  35. >function, not the left and right side of a comma-expression.  If
  36. >"x+1" is evaluated first, which is legal, it will use an
  37. >uninitialized "x.value".
  38. >
  39. >Don't write code which depends on unspecified order of evaluation.
  40. >
  41. >If there were no "op,()", the "," would mark a comma-expression,
  42. >and the "x=1" would have to be evaluated first; in that case the
  43. >whole expression would be well-defined.
  44.  
  45. The implication of what you say is that it is not possible to overload
  46. operators maintaining the correct functionality of the operator.  This
  47. indeed means that precedence in overloaded operators cannot be maintained
  48. if all operands are simply passed as arguments to the function implementing
  49. the operator functionality and evaluated in a language independent order.
  50. Imagine commonly used "chain" operators such as && and ║║.
  51.  
  52. If what is described above is correct, and Mr.Clamage clearly has much
  53. experience in the area, then I think we have justification for pressing
  54. for a change in this area.  If not, I would ask: How does one overload
  55. the comma operator while maintaining its attibutes as an operator?
  56.  
  57. Karl
  58.