Path: utzoo!attcan!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Multiple inheritance with virtual bases Message-ID: <488@taumet.com> Date: 22 Oct 90 15:00:34 GMT References: <1990Oct21.211143.3459@nowhere.uucp> Organization: Taumetric Corporation, San Diego Lines: 30 sking@nowhere.uucp (Steven King) writes: |In article |HAGIWARA.90Oct18105013@rd14.zuken.co.jp> hagiwara@zuken.co.jp (Kazuyuki Hagiwara) writes: |> [ ... ] |>struct A { |> char avar0[1000]; |>}; |>struct B : virtual public A { |> int bvar; |>}; |>struct C : virtual public A { |> int cvar; |>}; |>struct D : virtual public B, virtual public C { |> int dvar; |>}; | The definitions of B and C each have space for A allocated within them; |thus the size of D is sizeof B ( which is sizeof A + pointer overhead ) + |sizeof C ( sizeof A + pointer overhead ) + more pointer overhead. This is not correct. Exactly one instance of a virtual base class exists in an object by definition. Class A is declared to be virtual in all uses of it, so it is an error for there to be more than one copy. Let us hope that the error in this case is in the allocation, and that only one copy is ever referred to by generated code. -- Steve Clamage, TauMetric Corp, steve@taumet.com