title: virtual base class and initialization lists
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2126522/gcc-c-virtual-inheritance-problem">gcc c++ virtual inheritance problem</a>  </p>
  </blockquote>
  
  
  
  <p>Hi all,</p>
  
  <p>I'm wondering about how the compiler would handle different initialization values when using multiple inheritance from a virtual base class. Consider the notorious 'diamond of dread' inheritance scheme:</p>
  
  <pre><code>     Base
       / \
      /   \
    D1     D2
      \   /
       \ /
       Join
  </code></pre>
  
  <p>In order to avoid having two copies of <code>Base</code> in <code>Join</code>, I use virtual inheritance for <code>D1</code> and <code>D2</code> (see e.g. <a href="http://www.parashift.com/c++-faq-lite/multiple-inheritance.html" rel="nofollow noreferrer">here</a>). Now, lets say <code>Base</code> is not abstract, but has a member field, which is initialized in its constructor:</p>
  
  <pre><code>class Base { 
  public:
      Base(int x_) {x = x_;};
      virtual ~Base(){};
  
  public:
      int x;
  };
  
  class D1 : public virtual Base {
  public:
      D1() : Base(1) {};
      virtual ~D1(){};
  };
  
  class D2 : public virtual Base {
  public:
      D2() : Base(2) {};
      virtual ~D2(){};
  };
  
  class Join : public D1, public D2 {
  public:
      Join(){};
      ~Join(){};
  };
  
  int main()
  {
     Join j;
     cout &lt;&lt; j.x &lt;&lt; endl;
  
     return 0;
  }
  </code></pre>
  
  <p>Will the output be 1, 2, or is it compiler-dependent?</p>