home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11811 < prev    next >
Encoding:
Text File  |  1992-07-30  |  1.6 KB  |  60 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!mips!mips!munnari.oz.au!trlluna!titan!root
  3. From: root@trl.oz.au (System PRIVILEGED Account)
  4. Subject: Problem with C++ V3.0.1 on Sun3
  5. Message-ID: <1992Jul30.002138.28759@trl.oz.au>
  6. Organization: Telecom Research Labs, Melbourne, Australia
  7. Date: Thu, 30 Jul 1992 00:21:38 GMT
  8. Lines: 50
  9.  
  10. I have been trying to make C++ V3.0.1 on a sun 3. In fact the make
  11. has been successful (sort of). After installation I have tried to
  12. compile the following program
  13.  
  14. #include <iostream.h>
  15.  
  16. class    A {
  17.     public:
  18.         int    a;
  19.         operator int()    const {return a;}
  20.         friend ostream&    operator<<(ostream& o, const A&) {
  21.             return o;
  22.         }
  23. };
  24.  
  25. main()
  26. {
  27.     A    a;
  28.     cout << a << endl;
  29. }
  30.  
  31. My problem is that the compiler complains about an ambiguous operator
  32. << defined for
  33.     (ostream &, const A&) in the above source
  34. clashing with << defined for
  35.     (ostaream &, int) defined in iostream.h.
  36.  
  37. The problem is obviously caused by the int() operator in class A,
  38. and indeed removing this operator causes the problem to go away.
  39.  
  40. However:
  41. 1. I want to be able to do the above and believe taht I should be able
  42. to.
  43.  
  44. 2. The doco seems to indicate that what I have done is legal.
  45.  
  46. 3. The same sources compiled on a Sun 4 allow the above code to compile
  47. without hitch.
  48.  
  49. 4. (if relevent) It worked under CC V2.1.
  50.  
  51. Does anyone know offhand what I have done wrong?
  52. I would be very grateful for any leads.
  53.  
  54. Thanx ...mcf
  55.  
  56. Michael Flower
  57. Artificial Intelligence Systems         Email:     m.flower@trl.oz.au
  58. Telecom Research Laboratories           Voice:     +61 3 541 6179
  59. Melbourne, AUSTRALIA                    Fax:       +61 3 543 8863
  60.