Re: Why no access specifiers for friends?
goo.mail01@yahoo.com (Jiang) wrote (abridged):
Why we do not have access specifiers to control the protected
friends or private friends?
Because they are not really needed. The key point is that "friend" names a
single class rather than an open group of classes. In C++, if you want to
see how private members are used you have a lexically limited list of
places to look at - the class's members. "Friend" doesn't change that. It
just adds a few more places to look.
Inheritance is different to friendship in that there can be unboundedly
many subclasses. This is why subclasses can't be allowed access to private
members, and friends can.
To put it another way, to say that a friend can only access part of a
class's representation would be like saying the class's own members can
only access part of the representation. It defeats the purpose of the
class as the unit of access. If that's what you want, split it up into
multiple classes.
-- Dave Harris, Nottingham, UK.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]