Friend declarations: nested classes and base-clauses

Jul 10, 2010 at 4:02pm
Hi there!

I've got two questions about friend declarations.

1)

According to the 11.8.1 paragraph of C++03 standard:

The members of a nested class have no special access to members of an enclosing class, nor to classes or functions that have granted friendship to an enclosing class


How is it possible that a single function can grant friendship to a class ?

2)

My second question concerns a base-clause of a nested class.

We can read in C++0x standard draft (11.4.2 paragraph) that:

Declaring a class to be a friend implies that the names of private and protected members from the class granting friendship can be accessed in the base-specifiers and member declarations of the befriended class.
[ Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class A
{
    class B { };
    friend class X;
};

struct X : A::B //OK: A::B accessible to friend
{
    A::B mx; //OK: A::B accessible to member of friend
    class Y
    {
        A::B my; //OK: A::B accessible to nested member of friend
    };
};


—end example ]


It isn't mentioned in the example whether private and protected type names from the class granting friendship can be used in the base-clause of a nested class of the friend class (here it would be the base-clause of class Y).

I think they can, do you think so too ?

I can't check it by myself since I don't have any compatible with C++0x compilers...
Jul 10, 2010 at 4:40pm
I'm not certain how to answer #1, but I can give you my impression of #2: I don't think that is ok, by the rule you stated in #1: that nested classes have no special access to friend classes of the enclosing class.
Jul 10, 2010 at 5:12pm
Zhuge, remember that the second quotation concerns C++0x !

Moreover, if we're talking about C++03, the answer for #2 is Yes, they can ! I only don't know what about C++0x...
Jul 10, 2010 at 8:05pm
If you're certain, then I doubt they were remove something like that in 0x. Usually they try to avoid breaking existing code.
Jul 10, 2010 at 9:05pm
I don't understand...

Is it bad that someone can use a private name in the base-clause ?
Last edited on Jul 10, 2010 at 9:05pm
Jul 11, 2010 at 12:10am
You declared it a friend, so it has access to that. Am I understanding you right?
Jul 11, 2010 at 6:12am
Sorry, I misunderstood you before :) Thx for help.

Now, I only need an answer for 1#.
Jul 12, 2010 at 11:00am
Can somebody help me regarding 1# ?
Topic archived. No new replies allowed.