I am working on designing a small system and am wondering about a nuance of how memory is allocated for derived classes.
If I have two classes
class foo {
public: int a;
Foo(): a(0) {};
};
class bar : public foo {
public: int b;
Bar() : Foo() , b(0) {}
};
and then do something like this in another method
Bar* purple = new Bar();
I know that both constructors will be called (for Foo and Bar) but how will the memory be allocated. Is the memory for both 'a' and 'b' allocated at the same time, as they are both a part of Bar class, or is the memory allocated for 'a' when the Foo constructor is called and the memory for 'b' allocated when the Bar constructor is called.
Thanks in advance for the help.