title: C++ - downcasting a diamond shape inherited object without RTTI/dynamic_cast
body: <p>I'm currently working on integrating a third-party package that uses lots of RTTI stuff on a non-RTTI platform (Android). Basically, I did my own RTTI implementation but I'm stuck on a problem.</p>
  
  <p>The issue is that a lot of classes are having the diamond inheritance problem since all the classes derive from the same base class (object).. and so, if I want to downcast from the base class to the derived class, I have to use a dynamic_cast - but RTTI is not available! How do I convert an object from parent to child when there are virtual inheritance without dynamic_cast?</p>
  
  <p>It looks like that:</p>
  
  <pre><code>class A 
  {
  public:
   virtual char* func() { return "A"; };
  };
  class B : public virtual A
  {
  public:
   //virtual char* func() { return "B"; };
  };
  class C : public virtual A 
  {
  public:
   //virtual char* func() { return "C"; };
  };
  
  class D : public B, public C 
  {
  public:
   //virtual char* func() { return "D"; };
  };
  
  D d;
  A* pa = static_cast&lt;A*&gt;(&amp;d);
  D* pd = static_cast&lt;D*&gt;(pa); // can't do that! dynamic_cast does work though...
  </code></pre>
  
  <p>Those are my errors:</p>
  
  <blockquote>
    <p>error C2635: cannot convert a 'A*' to a 'D*'; conversion from a virtual base class is implied</p>
    
    <p>error C2440: 'initializing' : cannot convert from 'test_convert::A *' to 'test_convert::D *'
           Cast from base to derived requires dynamic_cast or static_cast</p>
  </blockquote>
  
  <p>Any ideas?</p>