fred@SABER.TERA.COM (12/22/89)
The GNU C++ compiler appears to allow access to data which violates C++ protection rules. The following two examples will illustrate the problem. These examples are taken from the Unix System V, AT&T C++ Language System Release 2.0 Selected Readings Manual, Chapter 7. class B { friend void f1(); public: int a; }; class C : private B { friend void f2(); }; class D : public C{}; void f1() { D* p1; p1->a=1; // This should be an error. } Since f1 is referencing 'a' from a pointer to a D object which is derived from a public C which is derived from a private B. This means that B::a is a private member of the derived class C. Only friends and members of C should have access to B::a in the derived class C. class B { int i; friend class D; }; class C : private B {}; class D : public C { void f() { int fi1=i; // This should be an error. } }; Again B::i is a private member of class C. Only public and protected members of the base class C are avaible to members and friends of the derived class D.