Newsgroups: comp.lang.c++
Path: utzoo!censor!geac!alias!fred!rae
From: Reid Ellis <rae@gpu.utcs.toronto.edu>
Subject: Re: Multiple inheritance with virtual bases
Message-ID: <rae.656801817@fred>
Sender: Reid Ellis <rae%alias@csri.toronto.edu>
Reply-To: Reid Ellis <rae@gpu.utcs.toronto.edu>
Organization: Alias Research, Inc. Toronto ON Canada
References: <1990Oct21.211143.3459@nowhere.uucp> <12342@cadillac.CAD.MCC.COM>
Date: 24 Oct 90 20:56:57 GMT

The source being discussed is appended at the end of this article
after a linefeed.  I noticed that the struct 'D' does not need to use
"virtual" for deriving from B and C [although it shouldn't matter for
this code] and tried removing them.

Under Apple's MPW C++ compiler, I get the previously mentioned cfront
output:
A 1000 B 1008 C 1008 D 2032

If, however, I change the line
"struct D : virtual public B, virtual public C {"
to
"struct D : public B, public C {"
then I get the more expected result of:
A 1000 B 1008 C 1008 D 1020

Hope this pins the problem down a bit more.  And if you need to, use
this as a workaround.
					Reid
Original source follows:

#include <stream.h>

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;
};

main() {
  cout << "A " << sizeof(A) 
    << " B " << sizeof(B) 
      << " C " << sizeof(C) 
	<< " D " << sizeof(D) << "\n";
}
--
Reid Ellis  264 Broadway Avenue, Toronto ON, M4P 1V9               Canada
rae@gpu.utcs.toronto.edu || rae%alias@csri.toronto.edu || +1 416 487 1383
