title: Downcast: why: ‘A’ is an inaccessible base of ‘B’?
body: <p>Unlike other examples of this error message i already have a pointer to <code>A</code> and want to retrieve the actual child class.</p>
  
  <p>This kind of arrangement is part of some C++ wrapped C code there <code>A</code> is some POD C structure (whatswhy no dynamic cast)  and <code>test</code> is some callback in C that calls C++ functionality and to retrieve the correct object the cast should be used.
  But to prevent C++ user code messing the C-Baseclass i would like to have the inheritance <code>protected</code>.</p>
  
  <p>MSVC does not complain about this but g++ does!?
  Which one is correct from the standards point of view and why?</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  // plain C structure
  struct A{
      int i;
  };
  
  // some C++ Wrapper class
  struct B: protected A{
    A* get() { return this; }
    void print(){cout &lt;&lt; i &lt;&lt; endl;}
  };
  
  
  
  extern "C" {
    // C callback that gives it this pointer
    void test(A* io_self){
       auto b2 = static_cast&lt;B*&gt;(io_self);
       b2-&gt;print();
    }
  }    
  
  int main()
  {
     B b;
     test(b.get());
     return 0;
  }
  </code></pre>
  
  <p>gives:</p>
  
  <pre><code>$g++ -std=c++11 -o main *.cpp
  main.cpp: In function ‘void test(A*)’:
  main.cpp:21:43: error: ‘A’ is an inaccessible base of ‘B’
            auto b2 = static_cast&lt;B*&gt;(io_self);
                                             ^
  </code></pre>