title: Calling a virtual base class's overloaded constructor
body: <p>Is there a (practical) way to by-pass the normal (virtual) constructor calling order?</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>class A
  {
      const int i;
  
  public:
      A()
        : i(0)
      { cout &lt;&lt; "calling A()" &lt;&lt; endl; }
  
      A(int p)
        : i(p)
      { cout &lt;&lt; "calling A(int)" &lt;&lt; endl; }
  };
  
  class B
      : public virtual A
  {
  public:
      B(int i)
        : A(i)
      { cout &lt;&lt; "calling B(int)" &lt;&lt; endl; }
  };
  
  class C
      : public B
  {
  public:
      C(int i)
        : A(i), B(i)
      { cout &lt;&lt; "calling C(int)" &lt;&lt; endl; }
  };
  
  class D
      : public C
  {
  public:
      D(int i)
        : /*A(i), */ C(i)
      { cout &lt;&lt; "calling D(int)" &lt;&lt; endl; }
  };
  
  
  int main()
  {
      D d(42);
      return 0;
  }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <blockquote>
    <p>calling A()<br>
    calling B(int)<br>
    calling C(int)<br>
    calling D(int)  </p>
  </blockquote>
  
  <p>What I want to have is something like:  </p>
  
  <blockquote>
    <p>calling A(int)<br>
    calling B(int)<br>
    calling C(int)<br>
    calling D(int)  </p>
  </blockquote>
  
  <hr>
  
  <p>As you see, there is virtual inheritance involved, which leads the constructor of D to call the constructor of A first, but since no parameter is provided, it calls A(). There's the <strong>const</strong> int i that needs initialisation, so I've got a problem.  </p>
  
  <p>What I'd like to do is to hide the inheritance details of C, that's why I'm looking for a way to avoid calling A(i) in D's (and every derived) constructor's initialisation list. [edit] In this specific case, I can assume there are only non-virtual single-inheritance child classes of C (as D is one). [/edit]</p>
  
  <p><strong>[edit]</strong></p>
  
  <blockquote>
    <p>Virtual base classes are initialized before any non-virtual base classes are initialized, so only the most derived class can initialize virtual base classes. – James McNellis  </p>
  </blockquote>
  
  <p>That's exactly the point, I <strong>don't</strong> want the most derived class to call the virtual base class constructor.
  <strong>[/edit]</strong></p>
  
  <p>Consider the following situation (<strong>not represented in the code example above</strong>):  </p>
  
  <pre><code>  A
   / \
  B0  B1
   \ /
    C
    |
    D  
  </code></pre>
  
  <p>I understand why C has to call the ctor of A (ambiguity) when you instantiate C, but why does D have to call it when instantiating D?  </p>