Re: Double abstract class Inheritance concern.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx    ::     http://www.planetfall.pwp.blueyonder.co.uk



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux