Re: Why no access specifiers for friends?
Gennaro Prota wrote:
On 19 Sep 2006 13:15:43 -0400, "kanze" <kanze@gabi-soft.fr> wrote:
Jiang wrote:
But it was not my intention to compare inheritance and
friend. I just want to now what is the rationale for ignoring
access control for friend declarations.
Probably because friendship is really a way of making a member
of something that could not otherwise be declared as a member:
there's really very little difference between a friend function
and a static member function, for example. As I tried to say, a
friend function belongs to your implementation.
But how do you conciliate that with your statement about introducing a
type of friendship which allowed access to only certain private
members? If it is a member it can access everything.
I don't, really:-). Except maybe that I might also like to be
able to introduce similar restrictions to member functions.
The first remark was really about the fact that control is on a
class basis. Be it friendship or the fact of being a member
functions, access is granted automatically to the entire class,
and not to parts of it. And there are times when one would like
to be more restrictive.
The second remark is really along the same lines (or perhaps a
consequence): like a member function, a friend function is part
of your implementation.
In the end, one can imagine many different levels of access: in
large applications, it is not unusually to define any number of
different "roles", to assign each user to one or more roles, and
each role to a different set of rights (access or modification).
And it's not unusual to want something more or less along these
lines for a class. The question is simple: how much extra
complexity would it entail, and is it worth it? For the moment,
I've not seen any concrete proposals to judge, but my impression
is that would introduce a lot of extra complexity. And that
given the relatively small size of classes, the benefits would
be minor.
--
James Kanze GABI Software
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]