lundi 7 décembre 2020

Is derived class object in memory stored as a whole or as a several connected objects? [duplicate]

class Base
{
//something
};

class Derived : public Base
{
//something more
};

void main()
{
Base b;
Derived d;
//...
}

How d looks in memory? Is it a one objects that have all data from Base and Derived, and destructor of Base is called only from Derived d-tor. Or is it two connected objects: object b and object, that has all data from Derived, so theoretically both that objects can be destroyed separately, and the other one stays "alive"?

Aucun commentaire:

Enregistrer un commentaire