title: In a diamond inheritance structure, is there a way to cast between the branches?
body: <p>I have a diamond inheritance structure in my code in which I have a pointer to the
  bottom object. I tried to case this to a pointer to the left of the two diamond sides, cast it again to the top of the diamond, and again to the right side. But apparently, C++ kind of remembers the order of casting and things don't work as expected. Example code:</p>
  <pre><code>#include &lt;iostream&gt;
  
  class A
  {
  };
  
  class B1 : public A
  {
  public:
      virtual int Return1() = 0;
  };
  
  class B2 : public A
  {
  public:
      virtual int Return2() = 0;
  };
  
  class C : public B1, public B2
  {
  public:
      virtual int Return1() { return 1; }
      virtual int Return2() { return 2; }
  };
  
  int main()
  {
      C c;
      B1* b1 = &amp;c;
      A* a = b1;
      B2* b2 = (B2*)a;
      std::cout &lt;&lt; &quot;Return2() = &quot; &lt;&lt; b2-&gt;Return2();
  }
  </code></pre>
  <p>This results in <code>Return2() = 1</code>, so apparently this approach is wrong. I know that something like this works in C#, so my question would be: Is there a way in C++ to do what I'm attempting here or - if not - why is this not an option?</p>