title: Virtual call from base in virtual inheritance
body: <p>I'm having a problem making a a virtual call when using virtual inheritance.</p>
  
  <p>Below is sample compilable code that demonstrates a code which works when there is no virtual inheritance used, and also code which will fail on runtime when virtual inheritance is used.</p>
  
  <p><strong>BASE CLASSES</strong>
  Here are base calsses for both cases:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Base
  {
  public:
      Base() { }
      virtual ~Base() { }
  
      // we need to make this bad call a good one!
      virtual void bad_call(void* ptr)
      {
          Base* pThis = static_cast&lt;Base*&gt;(ptr);
          pThis-&gt;f();
      }
  
  protected:
      virtual void f() { std::cout &lt;&lt; x &lt;&lt; std::endl; }
      int x = 0;
  };
  
  class Midle1 :
      virtual public Base
  {
  public:
      Midle1() { }
      ~Midle1() override { }
  };
  
  class Midle2 :
      virtual public Base
  {
  public:
      Midle2() { }
      ~Midle2() override { }
  };
  </code></pre>
  
  <p><strong>CASE 1 GOOD</strong>
  Here is a case which makes no use of virtual inheritance (just normal inheritance), where both <code>bad_call</code> and <code>good_call</code> virtual functions work:</p>
  
  <pre><code>class GoodDerived :
      public Base
  {
  public:
      GoodDerived()
      {
      }
      ~GoodDerived() override
      {
      }
      void good_call(void* ptr)
      {
          GoodDerived* pThis = static_cast&lt;GoodDerived*&gt;(ptr);
          pThis-&gt;f();
      }
  
      void f() override
      {
          ++x;
          std::cout &lt;&lt; x &lt;&lt; std::endl;
      }
  };
  
  int main()
  {
      GoodDerived good_derived;
      good_derived.good_call(&amp;good_derived);  // OK, will print 1
      good_derived.bad_call(&amp;good_derived);   // OK, will print 2
  
      std::cin.get();
      return 0;
  }
  </code></pre>
  
  <p><strong>CASE 2 BAD</strong>
  And here is a case which will make use of virtual inheritance, the <code>good_call</code> function will succeed, but <code>bad_call</code> one will fail with "access violation reading location"</p>
  
  <pre><code>class BadDerived :
      public Midle1,
      public Midle2
  {
  public:
      BadDerived() { }
      ~BadDerived() override { }
      void good_call(void* ptr)
      {
          BadDerived* pThis = static_cast&lt;BadDerived*&gt;(ptr);
          pThis-&gt;f();
      }
  
      void f() override
      {
          ++x;
          std::cout &lt;&lt; x &lt;&lt; std::endl;
      }
  };
  
  int main()
  {
      BadDerived bad_derived;
      bad_derived.good_call(&amp;bad_derived); // OK, will print 1
      bad_derived.bad_call(&amp;bad_derived); // ERROR: causes access violation
  
      std::cin.get();
      return 0;
  }
  </code></pre>
  
  <p><strong>QUESTION</strong>
  This second case is a simple code that demonstrated the issue I'm having right now in my project, and I need assistance on how to solve this, why is virtual inheritance causing troubles?</p>
  
  <p>Why first case works just fine but second one does not?</p>