This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Double abstract class Inheritance concern.


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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]