Double abstract class Inheritance concern.
Nathan Sidwell
nathan@codesourcery.com
Mon Mar 29 19:57:00 GMT 2004
Tiago Stein wrote:
>>Chris Lattner wrote:
>>
>>>Tiago Stein wrote:
>>>
>>>
>>>>class A{};
>>>>class B :public A{};
>>>>class C: public A{ int g; };
>>>>class D: public B, public C {
>>>> unsigned int foo;
>>>>};
>>>>Why sizeof class D is 12? Should not be 8?
>
>
> But is not only a single A present at D?
no, there are two.
> If I wanted separate A for each
> side of inheritance shouldn't I use virtual inheritance?
no you'd use that when you wanted one instance
> When I Use it..
> it adds even more size to the final class, so that I have more space used
> than is necessary to keep each onde witha separet adress.
yes, that is what the standard says.
> So if I understand correctly.. yhis is done to keep B and A with different
> addresses.. and not B::A and C::A ?
you do not understand correctly.
this is now no longer a g++ specific question, but one about C++. A C++
newsgroup would be appropriate to explore the whys of this requirement.
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
More information about the Gcc-help
mailing list