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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: Problem with C++ V3.0.1 on Sun3
  5. Message-ID: <1992Jul31.163725.9936@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <1992Jul30.002138.28759@trl.oz.au>
  8. Date: Fri, 31 Jul 1992 16:37:25 GMT
  9. Lines: 32
  10.  
  11. root@trl.oz.au (System PRIVILEGED Account) writes:
  12.  
  13. [ code simplified ]
  14.  
  15. | class    A {
  16. |     public:
  17. |         operator int();
  18. |         friend ostream&    operator<<(ostream&, const A&);
  19. | };
  20.  
  21. | main()
  22. | {
  23. |     A    a;
  24. |     cout << a << endl;
  25. | }
  26.  
  27. | My problem is that the compiler complains about an ambiguous operator
  28. | << defined for
  29. |     (ostream &, const A&) in the above source
  30. | clashing with << defined for
  31. |     (ostaream &, int) defined in iostream.h.
  32.  
  33. | The problem is obviously caused by the int() operator in class A,
  34. | and indeed removing this operator causes the problem to go away.
  35.  
  36. This is a compiler bug.  There is an exact match for the friend
  37. function, and a user conversion for the iostream.h function.  hte
  38. friend function should be preferred.
  39. -- 
  40.  
  41. Steve Clamage, TauMetric Corp, steve@taumet.com
  42. Vice Chair, ANSI C++ Committee, X3J16
  43.