lundi 7 décembre 2020

Is there any difference in memory layout for composition vs inheritance?

struct A
{
int a, b, c;
int fa() { /*something*/}
};

struct B1 : A
{
int a1, b1, c1;
int ba() { /*something */}
};

struct B2
{
A a;
int fa() {a.fa();}
int a2, b2, c2;
int ba() { /*something */}
};

void main()
{
B1 b1;
B2 b2;
//something
}

Will b1 and b2 have same layout in the memory? And in class B2 I basically did everything that is done by the compiler when I use inheritance?

Aucun commentaire:

Enregistrer un commentaire