M
munna
Considering the classic diamond problem in where we have this
relationship,
A
/ \
B C
\ /
D
and define our classes like the following:
class A{
public:
virtual void f1(){}
};
class B: public virtual A{
public:
void f1(){}
};
class C: public virtual A{
public:
void f1(){}
};
class D: public B, public C{
public:
void f1(){}
};
Specifically how the memory-layout for class D-object would be laid
out (in practice). Or is it so that since the standard doesn't
mandates any specific layout, compilers are free to have it at their
discretion? What i understand is that size of class A would be 4 bytes
(on a 32-bit architecture), sizeof B and C would be 8 bytes (one vptr
for B/C and one pointer to virtual base class A). How exactly would a
D object look like?
relationship,
A
/ \
B C
\ /
D
and define our classes like the following:
class A{
public:
virtual void f1(){}
};
class B: public virtual A{
public:
void f1(){}
};
class C: public virtual A{
public:
void f1(){}
};
class D: public B, public C{
public:
void f1(){}
};
Specifically how the memory-layout for class D-object would be laid
out (in practice). Or is it so that since the standard doesn't
mandates any specific layout, compilers are free to have it at their
discretion? What i understand is that size of class A would be 4 bytes
(on a 32-bit architecture), sizeof B and C would be 8 bytes (one vptr
for B/C and one pointer to virtual base class A). How exactly would a
D object look like?