title: How and why is it possible to change access level of a member?
body: <p>I ended up coding (With some help) something like this yesterday:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  using namespace std;
  
  class A
  {
      public:
          virtual void foo(){cout &lt;&lt; "A::foo\n";}
  };
  
  class B : private A
  {
      private:
          virtual void foo(){ cout &lt;&lt; "B::foo\n";}
          void DoSomething(SomeOtherClass&amp; o){o.DoSomething(*static_cast&lt;A*&gt;(this));}
  };
  </code></pre>
  
  <p>I tried changing the inheritance method:</p>
  
  <pre><code>class B : public A
  {
      private:
          virtual void foo(){ cout &lt;&lt; "B::foo\n";}
  };
  
  int main()
  {
      A* a = new B;
      a-&gt;foo();
  }
  </code></pre>
  
  <p>This still works. I expected a compile time error. Please tell me why this is possible and what are the possible uses? I know one use due to first scenario - You can expose different interfaces for different classes.</p>
  
  <p>EDIT:</p>
  
  <p>In the second case, output is <code>B::foo</code>.</p>