Path: utzoo!attcan!uunet!mcvax!cernvax!ethz!marti From: marti@ethz.UUCP (Robert Marti) Newsgroups: comp.lang.c++ Subject: Access of protected members thru friends Keywords: bug or not? Message-ID: <868@ethz.UUCP> Date: 12 May 89 09:24:30 GMT Organization: ETH Zuerich Lines: 41 Consider the following scenario: class Base { protected: int data; // ... }; class Derived : public Base { friend int friendFunc(Derived d); friend class FriendClass; // ... }; int friendFunc(Derived d) { return d.data; // <<<<< error: data is protected } class FriendClass { public: int func(Derived d); // ... }; int FriendClass::func(Derived d) { return d.data; // <<<<< error: data is protected } cfront 1.2.1 issues two error messages "data is protected" (indicated by <<<<< above). Why? It seems that since a friend of a class has access to all members visible in that class and "inherited" protected members are visible in derived classes, d.data should be visible and accessible in friendFunc and FriendClass::func. -- Robert Marti Phone: +41 1 256 52 36 Institut fur Informationssysteme ETH-Zentrum CSNET/ARPA: marti%inf.ethz.ch@relay.cs.net CH-8092 Zurich, Switzerland UUCP: ...uunet!mcvax!ethz!marti