home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!psinntp!factory!chris.sokol
- From: chris.sokol@factory.com (Chris Sokol)
- Newsgroups: comp.lang.c++
- Subject: Who is wrong? me, BC , G
- Message-ID: <7249.1635.uupcb@factory.com>
- Date: 11 Dec 92 03:15:00 GMT
- Distribution: world
- Organization: Invention Factory's BBS - New York City, NY - 212-274-8298v.32bis
- Reply-To: chris.sokol@factory.com (Chris Sokol)
- Lines: 49
-
- 48ganelin@cua.edu writes:
-
- >The next small program compiles with GNUC but not with BorlandC 2.0 &3.1
- >and not with SGI CC compiler.
- >(Of course, linker error with GNUC because += not defined ).
-
- >-------------------cut here ------------------
-
- >class A
- >{
- >public:
- > A & operator += ( const A & x ) ;
- >};
-
- >class B : public A
- >{
- >public:
- > B & operator += ( const int x ) ;
- >};
-
- >void main ()
- >{
- > B x , y ;
- > x += y ; // BorlandC complains here !!!!
- >}
-
- >--------------cut here --------------------------
- >Because two out of three used compilers refused to compile it I
- > expect that standart does not allow to do such thing.
-
- >WHY !!!!!
-
- >I read that every time I should use " BaseClass & "
- >I can always use " DerivedClass& ".
-
- >Is it true ? If yes what is wrong with the above program ?
-
- If you wish to use a method of class B which has been derived from class A by
- name, several dos compilers (BC/Zortech) complain if the overloading function
- does not take the same number/type of parameters.
-
- The fix is to specify the operator to be used, as in:
-
- A::x += y;
-
- chris.sokol@factory.com
- ---
- . SLMR 2.1a . Recursive, adj.: see Recursive.
-
-