title: Writing a Default Constructor Forces Zero-Initialization?
body: <p>These are my class definitions:</p>
  
  <pre><code>class Foo{
      int _ent;
  public:
      void printEnt() const{cout &lt;&lt; _ent &lt;&lt; ' ';}
  };
  
  class Bar{
      Foo _foo;
  public:
      void printEnt() const{_foo.printEnt();}
  };
  </code></pre>
  
  <p>And this is my test code:</p>
  
  <pre><code>char* buf = new char[sizeof(Foo) + sizeof(Foo) + sizeof(Bar)];
  
  fill(buf, buf + sizeof(Foo) + sizeof(Foo) + sizeof(Bar), 'J');
  
  cout &lt;&lt; ((int*)buf)[0] &lt;&lt; ' ' &lt;&lt; ((int*)buf)[1] &lt;&lt; ' ' &lt;&lt; ((int*)buf)[2] &lt;&lt; endl;
  
  Foo* first = new (buf) Foo;
  Foo* second = new (buf + sizeof(Foo)) Foo();
  Bar* third = new (buf + sizeof(Foo) * 2) Bar;
  
  first-&gt;printEnt(); second-&gt;printEnt(); third-&gt;printEnt();
  </code></pre>
  
  <p>My output is:</p>
  
  <blockquote>
    <p>1246382666 1246382666 1246382666<br>
    1246382666 0 1246382666</p>
  </blockquote>
  
  <p>But if I add a <code>public</code> default ctor to <code>Foo</code>: <code>Foo() : _ent(0) {}</code></p>
  
  <p>My output becomes:</p>
  
  <blockquote>
    <p>1246382666 1246382666 1246382666<br>
    0 0 0</p>
  </blockquote>
  
  <p><strong>Is this correct behavior? Should adding my own default ctor remove the possibility of default initialization?</strong></p>
  
  <p>I'm running this code on gcc 4.8.1 if it matters. The results should be dependable because I'm running in debug and asserting: <code>assert(sizeof(Foo) == sizeof(int) &amp;&amp; sizeof(Bar) == sizeof(int));</code></p>