home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17879 < prev    next >
Encoding:
Internet Message Format  |  1992-12-12  |  1.6 KB

  1. Path: sparky!uunet!psinntp!factory!chris.sokol
  2. From: chris.sokol@factory.com (Chris Sokol) 
  3. Newsgroups: comp.lang.c++
  4. Subject: Who is wrong? me, BC , G
  5. Message-ID: <7249.1635.uupcb@factory.com>
  6. Date: 11 Dec 92 03:15:00 GMT
  7. Distribution: world
  8. Organization: Invention Factory's BBS - New York City, NY - 212-274-8298v.32bis
  9. Reply-To: chris.sokol@factory.com (Chris Sokol) 
  10. Lines: 49
  11.  
  12. 48ganelin@cua.edu writes:
  13.  
  14. >The next small program compiles with GNUC but not with BorlandC 2.0 &3.1
  15. >and not with SGI CC compiler.
  16. >(Of course, linker error with GNUC because += not defined ).
  17.  
  18. >-------------------cut here ------------------
  19.  
  20. >class A
  21. >{
  22. >public:
  23. >  A & operator += ( const A & x ) ;
  24. >};
  25.  
  26. >class B : public A
  27. >{
  28. >public:
  29. >  B & operator += ( const int x ) ;
  30. >};
  31.  
  32. >void main ()
  33. >{
  34. > B  x , y ;
  35. > x += y ;            //  BorlandC complains here !!!!
  36. >}
  37.  
  38. >--------------cut here --------------------------
  39. >Because two out of three used compilers refused to compile it I
  40. > expect that standart does not allow to do such thing.
  41.  
  42. >WHY !!!!!
  43.  
  44. >I read that every time I should use   " BaseClass & "
  45. >I can always use " DerivedClass& ".
  46.  
  47. >Is it true ? If yes what is wrong with the above program ?
  48.  
  49. If you wish to use a method of class B which has been derived from class A by
  50. name, several dos compilers (BC/Zortech) complain if the overloading function
  51. does not take the same number/type of parameters.
  52.  
  53. The fix is to specify the operator to be used, as in:
  54.  
  55. A::x += y;
  56.  
  57. chris.sokol@factory.com
  58. ---
  59.  . SLMR 2.1a . Recursive, adj.: see Recursive.
  60.                                                                                                                           
  61.