Consider the below simple program of inheritance
#include <iostream>
class A
{
};
class B : public A
{
};
class C : public B
{
};
int main()
{
C x;
}
Now my question is
- How many objects are created ? One or three?
- Also, in case one object, does it mean it creates a layered object ?
What I wanted to ask was ,when we call constructor of base classes , what is happening as we have only one object (from the object perspective) ? What all things C object x will have ,and what all things are deleted when destructors of base class is called? How is memory allocated for C's object?
Just to make everyone know ,I do understand
When we are creating an object of the derived class, we end up with one object only .
But the question is ,internally do the derived class object c will wrap the two objects of A and B or , will just public/protected attributes will be copied to the object.
Also is the below line correct?
"When we declare a object on the stack or use new first the memory is reserved and object is created, then the constructors are executed, starting with the base constructor and working upwards towards the most derived class ?"