This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: g++: Too deep virtual inherance


On Jan 13, 2000, Francois Bertel <fbertel@irisa.fr> wrote:

> The problem: g++ seems to have problem during construction when the
> inherance is too deep and when this inherance is virtual:

Welcome to C++ :-)

In C++, virtual inheritance implies any directly or indirectly
virtually-inherited class must be initialized by the most derived
class.  Initializers in superclass constructors are silently ignored.
So, given the following code snippet:

struct base { foo() {} foo(int) {} };
struct mid : virtual base { mid() : base(1) {} };
struct derived : mid { derived() : /* base(), */ mid() {} };

the `base(1)' is only used when an instance of `mid' is constructed,
but not when a subclass of `mid' is created.  When `derived' is
instantiated, it becomes responsible for initializing base().  Since
an initializer of base is omitted (commented out), default
initialization takes place.

-- 
Alexandre Oliva http://www.ic.unicamp.br/~oliva IC-Unicamp, Bra[sz]il
oliva@{lsd.ic.unicamp.br,guarana.{org,com}} aoliva@{acm,computer}.org
oliva@{gnu.org,kaffe.org,{egcs,sourceware}.cygnus.com,samba.org}
** I may forward mail about projects to mailing lists; please use them


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]