title: Use of virtual inheritance outside diamond inheritance problem to allow leapfrogging
body: <p>Consider the following program:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  class B
  {
  public:
      int n;
  
      B() : n(0) {}
      B(int m) : n(m) {}
  };
  
  class D1 : virtual public B
  {
  public:
      int a;
      
      D1() : a(0) {}
      D1(int m) : a(m) {}
  };
  
  class D2 : public D1
  {
  public:
      int d;
      
      D2() : d(0) {}
      D2(int m) : d(m) {}
      D2(int j, int k) : d(j), D1(k) {}
      D2(int i, int j, int k) : d(i), D1(j), B(k) {}  //Without virtual inheritance,
                                                      //must add new constructor to D1.
  };
  
  int main()
  {
      std::string s;
      D2 d2(0, 1, 2);
      
      std::cout &lt;&lt; &quot;d2.n = &quot; &lt;&lt; d2.n &lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;d2.a = &quot; &lt;&lt; d2.a &lt;&lt; &quot;\n&quot;;
      std::cout &lt;&lt; &quot;d2.d = &quot; &lt;&lt; d2.d &lt;&lt; &quot;\n&quot;;
      
      std::cout &lt;&lt; &quot;Press ENTER to exit.\n&quot;;
      getline(std::cin, s);
  }
  </code></pre>
  <p>Having D1 inherit virtually from B allows me to call the constructor of B from the constructor of D2, leapfrogging over the class D1.</p>
  <p>Can this use of virtual inheritance apart from the diamond-inheritance problem cause undefined behavior or other harm?</p>
  <p>I have never seen virtual inheritance used except to solve the diamond inheritance problem.</p>