title: Understanding virtual base classes and constructor calls
body: <p>I'm a bit confused about how virtual base classes work.  In particular, I was wondering how the constructor of the base class gets called.  I wrote an example to understand it:</p>
  
  <pre><code>#include &lt;cstdio&gt;
  #include &lt;string&gt;
  using std::string;
  
  struct A{
      string s;
      A() {}
      A(string t): s(t) {}
  };
  
  struct B: virtual public A{
      B(): A("B"){}
  };
  
  struct C: virtual public A {};
  
  struct D: public B, public C {};
  
  struct E: public C, public B {};
  
  struct F: public B {};
  
  int main(){
      D d;
      printf("\"%s\"\n",d.s.c_str());
      E e;
      printf("\"%s\"\n",e.s.c_str());
      F f;
      printf("\"%s\"\n",f.s.c_str());
      B b;
      printf("\"%s\"\n",b.s.c_str());
  }
  </code></pre>
  
  <p>Which outputs</p>
  
  <pre><code>""
  ""
  ""
  "B"
  </code></pre>
  
  <p>I wasn't sure what would happen in the first two cases, but for the third one at least I was expecting the output to be "B".  So now I'm just confused.  What are the rules for understanding how the constructor of A gets called?</p>