title: Memory Allocation for Derived C++ classes
body: <p>I am working on designing a small system and am wondering about a nuance of how memory is allocated for derived classes.</p>
  
  <p>If I have two classes</p>
  
  <pre><code>class foo {
  public: int a;
  Foo(): a(0) {};
   };
  class bar : public foo {
  public: int b;
  Bar() : Foo() , b(0) {}
  };
  </code></pre>
  
  <p>and then do something like this in another method</p>
  
  <pre><code>Bar* purple = new Bar();
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks in advance for the help.</p>