#include <stdio.h>

class A {
protected:
    int prot;
public:
    int pub;
    A() : prot(0), pub(0) {}
    void Print() const { printf("  prot = %d, pub = %d\n", prot, pub); }
};

/* public all the way: A <- B1 <- C1 */
class B1 : public A {
public:
    void f() { prot = 1; pub = 1; }     /* direct descendant: fine */
};

class C1 : public B1 {
public:
    void g() { prot = 2; pub = 2; }     /* far descendant: fine too */
};

/* private in the middle: A <- B2 <- C2 */
class B2 : private A {
public:
    void f() { prot = 1; pub = 1; }     /* direct descendant: fine */
    void Show() const { Print(); }      /* B2 decides what to expose */
};

class C2 : public B2 {
public:
#ifdef ERRORS
    void g() { prot = 2; pub = 2; }     /* line 33 */
    void h() { ::A *p = this; (void)p; }        /* line 34 */
#endif
};

int main()
{
    C1 c1;
    C2 c2;

    printf("C1 (public chain):\n");
    c1.f();
    c1.g();
    c1.Print();                         /* A's method, from outside */

    printf("C2 (private in the middle):\n");
    c2.f();                             /* B2's own public method */
    c2.Show();
#ifdef ERRORS
    c2.g();
    c2.Print();                         /* line 53 */
#endif
    return 0;
}
