home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / sgi / bugs / 20 < prev    next >
Encoding:
Text File  |  1992-12-21  |  2.6 KB  |  120 lines

  1. Newsgroups: comp.sys.sgi.bugs
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!teal.csn.org!fop
  3. From: fop@teal.csn.org (J. Gabriel Foster)
  4. Subject: c++ question/bug?
  5. Message-ID: <BzH1r2.BBw@csn.org>
  6. Summary: problem with overloading and enclosed classes
  7. Keywords: c++
  8. Sender: news@csn.org (news)
  9. Nntp-Posting-Host: teal.csn.org
  10. Organization: GW Hannaway & Associates, Inc.
  11. Date: Fri, 18 Dec 1992 20:18:34 GMT
  12. Lines: 106
  13.  
  14. Hello,
  15.     I have a question about CC 3.0.  I am trying to overload the << function
  16.     on a class that is enclosed within another class.  As far as I can tell
  17.     from Ellis & Stroustrup's "The Annotated C++ Reference Manual" this
  18.     is a valid thing to do.  For an example of my problem, look at 
  19.     test1.c and test2.c (given below). test1.c compiles, but test2.c does
  20.     not.  Why does test2.c not work?  My compiler versions and example
  21.     source code follow.
  22.  
  23. Thank you for your time,
  24.     --> Gabe Foster
  25.  
  26. > J. Gabriel Foster (fop@gwha.com)
  27. > GW Hannaway & Associates, 839 Pearl Street, Boulder, CO 80302
  28. > Voice: (303)440-9631, Fax: (303)440-4421
  29.  
  30.  
  31. fop@spice<1>versions -n c++
  32. I = Installed, R = Removed
  33.  
  34.    Name                 Version   Description
  35.  
  36. I  c++                 707182570  C++, 3.0
  37. I  c++.hdr            1006310004  C++ Headers
  38. I  c++.hdr.lib        1006310004  C++ Library Headers
  39. I  c++.man            1006310004  C++ Manual Pages
  40. I  c++.man.c++        1006310004  C++ Compiler Man Pages
  41. I  c++.man.relnotes   1006310004  C++ Release Notes
  42. I  c++.sw             1006310004  C++ Software
  43. I  c++.sw.c++         1006310004  C++ Compiler
  44. I  c++.sw.lib         1006310004  C++ Libraries
  45. I  c++.sw.libC        1006310004  C++ library
  46. fop@spice<2>cat test1.c
  47. // test1.c
  48. // version WITHOUT name space protection via an enclosing class
  49. class AA {
  50. public:
  51.     AA& operator<<( int v ) { v = v; return *this; }
  52. };
  53.  
  54. class AAA {
  55.     friend AA& operator<<( AA& aa, AAA& v );
  56. };
  57.  
  58. class AAB {
  59.     friend AA& operator<<( AA& aa, AAB& v );
  60. };
  61.  
  62. AA&
  63. operator<<( AA& aa, AAA& v )
  64. {
  65.     v = v;
  66.     return aa;
  67. }
  68.  
  69. AA&
  70. operator<<( AA& aa, AAB& v )
  71. {
  72.     v = v;
  73.     return aa;
  74. }
  75.  
  76. main( ) 
  77. {
  78. }
  79. fop@spice<3>CC test1.c
  80. fop@spice<4>cat test2.c
  81. // test2.c
  82. // version WITH name space protection via an enclosing class
  83. class A {
  84. public:
  85.     class AA {
  86.     public:
  87.         AA& operator<<( int v ) { v = v; return *this; }
  88.     };
  89.  
  90.     class AAA {
  91.         friend AA& operator<<( AA& aa, AAA& v );
  92.     };
  93.  
  94.     class AAB {
  95.         friend AA& operator<<( AA& aa, AAB& v );
  96.     };
  97. };
  98.  
  99. A::AA&
  100. operator<<( A::AA& aa, A::AAA& v )
  101. {
  102.     v = v;
  103.     return aa;
  104. }
  105.  
  106. A::AA&
  107. operator<<( A::AA& aa, A::AAB& v )
  108. {
  109.     v = v;
  110.     return aa;
  111. }
  112.  
  113. main( ) 
  114. {
  115. }
  116. fop@spice<5>CC test2.c
  117. "test2.c", line 25: error: two definitions of operator <<()
  118. fop@spice<6>
  119.  
  120.