This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++: Too deep virtual inherance
- To: Francois Bertel <fbertel at irisa dot fr>
- Subject: Re: g++: Too deep virtual inherance
- From: Alexandre Oliva <oliva at lsd dot ic dot unicamp dot br>
- Date: 13 Jan 2000 17:26:08 -0200
- Cc: gcc-bugs at gcc dot gnu dot org
- References: <387DDF6A.3B961EBD@irisa.fr>
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