home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.g++.bug
- Path: sparky!uunet!cis.ohio-state.edu!algorithmics.COM!jody
- From: jody@algorithmics.COM (Jody Goldberg)
- Subject: Inheritance bug
- Message-ID: <9211200051.AA20878@lira>
- Sender: gnulists@ai.mit.edu
- Organization: Gnus Not Usenet
- Distribution: gnu
- Date: Thu, 19 Nov 1992 14:51:00 GMT
- Approved: bug-g++@prep.ai.mit.edu
- Lines: 111
-
- Using gcc-2.3.1 on a Sparc II running 4.1.3 with libg++-2.2 the following code
- produces.
- ---------------------------------------------
- g++ -v
- Reading specs from /usr/local/lib/gcc-lib/sparc-sun-sunos4.1/2.3.1/specs
- gcc version 2.3.1
- ---------------------------------------------
- g++ Test.C ; ./a.out
- ----------
- 3
- 3
- ---------------------------------------------
- We expected
- -----------
- 1
- 2
- ------------------------
- Test.H
- ------
- #include <iostream.h>
-
- class A
- {
- public:
- virtual ~A();
- virtual int type(void);
- };
-
- class B
- {
- public:
- virtual ~B();
- };
-
-
- class C0 : public B, public A
- {
- public:
- int type(void);
- };
-
- class C1 : public C0
- {
- public:
- int type(void);
- };
-
- class C2 : public C0
- {
- public:
- int type(void);
- };
-
- class C3 : public C0
- {
- public:
- int type(void);
- };
- ----------------------------
- Test.C
- ------
-
- #include "Test.H"
-
- A::~A()
- {
- }
-
- int A::type(void)
- {
- return 1;
- }
-
- B::~B()
- {
- }
-
- int C0::type(void)
- {
- return 0;
- }
-
- int C1::type(void)
- {
- return 1;
- }
-
- int C2::type(void)
- {
- return 2;
- }
-
- int C3::type(void)
- {
- return 3;
- }
-
- main()
- {
- C1* one = new C1;
- C2* two = new C2;
-
- cerr << one->type() << '\n';
- cerr << two->type() << '\n';
- }
-
- Thanks
- jody Goldberg
-
- jody@algorithmics.com
-
-