Why does C style cast allow you to convert to a private base class?
<p>Say we have this code</p>

<pre><code>class A {
public:
    A() : x(1) {}
    virtual ~A() {}

    int x;
};

class B {
public:
    B() : y(2) {}
    virtual ~B() {}

    void g()
    {
        cout &lt;&lt; "B::" &lt;&lt; y &lt;&lt; endl;
    }

    int y;
};

class C : private A, private B {
public:
    void f()
    {
        B* p = static_cast&lt;B*&gt;( this );
        p-&gt;g();
    }
};

int main()
{
    C c;
    ((B*)&amp;c)-&gt;g();

    return 0;
}
</code></pre>

<p>The C style cast in the main function cannot be correctly expressed in terms of the C++ casts (<code>static_cast</code>, <code>dynamic_cast</code>, <code>reinterpret_cast</code>). But what is the reason to allow this in the first place? Doesn't it hurt encapsulation?</p>
