🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

3 total messages Started by chatty%FRLRI61.BITNET Mon, 05 Jun 1989 15:39
bug caused by multiple inheritance
#2069
Author: chatty%FRLRI61.BITNET
Date: Mon, 05 Jun 1989 15:39
62 lines
2036 bytes
In the following example, a class B derives from a class A, and a class D derive
from class B and another class C. It seems that the presence of D confuses g++ 1
when managing simple inheritance of B from A : inherited members are called with
a wrong 'this' address.

% cat bug.cc
class A {
public:
                A () {};
        void    foo () { printf ("this = %x\n", this); }
};

class B : public A {
public:
                B () { printf ("this = %x\n", this); }
};

class C {
public:
        C ();
};

class D : public C, public B {
public :
                D ();
};


main ()
{
        B b;

        b.foo ();
}

% g++ -v -o bug bug.cc
g++ version 1.35.0+
 /usr/local/lib/GNU/cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dmc6800
0 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -Dmc68020 bug.cc /tmp/cca03288
.cpp
GNU CPP version 1.35
 /usr/local/lib/GNU/cc1plus /tmp/cca03288.cpp -quiet -dumpbase bug.cc -noreg -ve
rsion -o /tmp/cca03288.s
GNU C++ version 1.35.0+ (68k, MIT syntax) compiled by GNU C version 1.35.
In method void A::foo ():
bug.cc:4: warning: implicit declaration of function `printf'
 as -mc68020 /tmp/cca03288.s -o bug.o
 /usr/local/lib/GNU/ld++ -o bug -C /usr/local/lib/GNU/crt0+.o /lib/Fcrt1.o bug.o
 -lg++ /usr/local/lib/GNU/gnulib -lc

% bug
this = efffa86
this = efffa88

Surprising, ain't it ?

BTW, I would like more infos on the new 'protected virtual' feature. Is it norma
derived class cannot use the virtual functions of its base class ?

Stephane Chatty         chatty@frlri61.fr
                        chatty@lri.lri.fr
protected members (was: bug caused by multiple inheritance)
#2073
Author: Richard Murphey
Date: Mon, 05 Jun 1989 23:45
15 lines
1055 bytes
> derived class cannot use the virtual functions of its base class ?
> 
> Stephane Chatty         chatty@frlri61.fr


Weiner, Richard S. and Lewis J. Pinson. An Introduction to Object Oriented Programming and C++. Reading Mass.: Addison-Wesley, 1988. (ISBN 0-201-15413-7)

According to the text, protected class members are hidden in the same way as private members except in drived classes.  The scope of protected members includes the derived classes as well as the parent class. 

If anyone has other references on use of protected members, I'd also be interested.

Rich Murphey
Electrical Engineering
Rice University
rich@rice.edu
Re: bug caused by multiple inheritance
#2075
Author: Joseph E. Sacco
Date: Wed, 07 Jun 1989 02:00
15 lines
1133 bytes
In article <8906051539.AA18913@lri.lri.fr>, chatty%FRLRI61.BITNET@CUNYVM.CUNY.EDU writes:
> 
> In the following example, a class B derives from a class A, and a class D derive
> from class B and another class C. It seems that the presence of D confuses g++ 1
> when managing simple inheritance of B from A : inherited members are called with
> a wrong 'this' address.
> 

Another aspect of the bug is that not only does its existence depend upon
the declaration of D but also upon the order in which the parents of D are
specified. If that order is reversed the two values of "this" are seen to
be identical. Hmmmm ....................! What gives ?


						JOE
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads