Two questions on the proposed resolution for DR 45:
1) The first proposed amendment to class.access is to add:
"A member of a class can also access all names as the class of which it
is a member. A local class of a member function may access the same
names that the member function itself may access. [Footnote: Access
permissions are thus transitive and cumulative to nested and local
"A member of a class" can also mean a completely unrelated class, can it
not? For example:
// ... whatever ...
't' is a member of U - does that mean that it has access to U's members?
I doubt that is the intent of the proposed amendment, yet the proposed
wording seems to imply that it does.
How about restricting the wording a little:
"A member of a nested class can..."
In any case, even if I'm wrong and t cannot access U's members, I think
adding the word "nested" makes the intent of the sentence much clearer.
I had to read it three or for times and write out an example before I
figured out the intent.
2) Were there any strong reasons that the alternate proposal by Alan
Griffiths and Mark Radford (N1268) was not adopted? I know I'm dredging
up a discussion that was probably laid to rest over three years ago, but
I'm hoping someone remembers the discussion ;=)
N1268 covers the same points as the proposed resolution (N1254), but has
a far less invasive reach. In other words, if N1268 were to be adopted,
it would be trivial to later adopt N1254. On the other hand, adopting
N1254 effectively closes the door to adopting N1268. Consider:
friend class Outer;
Under N1268, SecondInner does not have any special privileges WRT
FirstInner, unless FirstInner explicitly grants them:
friend class Outer;
friend class SecondInner;
and that, IMO, is the way it should be - a class declares who its
friends are, regardless whether the class is "free-standing" or nested
inside another class.
If N1268 is found to be insufficient and it is later decided to adopt
N1254, then the above code still works, and the "friend class
SecondInner;" declaration is simply redundant.
Under N1254, though, if FirstInner declars Outer to be a friend, then
because of the transitivity granted in the amendment quoted above,
SecondInner is automatically granted access to all members of FirstInner
- and there is no way to prevent that. Worse, if it turns out allowing
this transitivity is a mistake, then any changes to the standard will
break any code which takes advantage of the implicit friendship.
Wouldn't it be prudent to take the more conservative approach of N1268,
since it solves all the same problems?
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:email@example.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.yqcomputer.com/