home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / std / cplus / 1155 < prev    next >
Encoding:
Text File  |  1992-09-11  |  2.1 KB  |  59 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 15:42:16 CET
  4. From: Karl Keyte <KKEYTE@ESOC.BITNET>
  5. Message-ID: <92255.154216KKEYTE@ESOC.BITNET>
  6. Newsgroups: comp.std.c++
  7. Subject: Re: Answers on a postcard
  8. Lines: 49
  9.  
  10. ...from a posting on 'comp.lang.c++'
  11.  
  12. In article <1992Sep10.174914.838@taumet.com>, steve@taumet.com (Steve Clamage)
  13. says:
  14. >
  15. >Karl Keyte <KKEYTE@ESOC.BITNET> writes:
  16. >
  17. >|#include <iostream.h>
  18. >
  19. >|class X {
  20. >|   private:    int           value;
  21. >|   public:     int           operator , (int i) { return i+10; };
  22. >|               int           operator + (int i) { return value+i; };
  23. >|               X &           operator = (int i) { value=i; return *this; };
  24. >|};
  25. >
  26. >
  27. >|void main()
  28. >|{
  29. >|   X         x;
  30. >
  31. >|   cout << "Value is " << (x=1, x+1) << endl;
  32. >|}
  33. >
  34. >In the expression in parens, it is unspecified whether "x=1" or
  35. >"x+1" is evaluated first.  They are arguments to the "operator,()"
  36. >function, not the left and right side of a comma-expression.  If
  37. >"x+1" is evaluated first, which is legal, it will use an
  38. >uninitialized "x.value".
  39. >
  40. >Don't write code which depends on unspecified order of evaluation.
  41. >
  42. >If there were no "op,()", the "," would mark a comma-expression,
  43. >and the "x=1" would have to be evaluated first; in that case the
  44. >whole expression would be well-defined.
  45.  
  46. The implication of what you say is that it is not possible to overload
  47. operators maintaining the correct functionality of the operator.  This
  48. indeed means that precedence in overloaded operators cannot be maintained
  49. if all operands are simply passed as arguments to the function implementing
  50. the operator functionality and evaluated in a language independent order.
  51. Imagine commonly used "chain" operators such as && and ║║.
  52.  
  53. If what is described above is correct, and Mr.Clamage clearly has much
  54. experience in the area, then I think we have justification for pressing
  55. for a change in this area.  If not, I would ask: How does one overload
  56. the comma operator while maintaining its attibutes as an operator?
  57.  
  58. Karl
  59.