marti@ethz.UUCP (Robert Marti) (05/12/89)
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