Friend declarations: nested classes and base-clauses
Hi there!
I've got two questions about friend declarations.
1)
According to the 11.8.1 paragraph of C++03 standard:
Quote:
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:
Quote:
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:
Code:
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...
Re: Friend declarations: nested classes and base-clauses
Quote:
Originally Posted by
Quentin026
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).
What's base-clause? Did you mean base class?
That would mean that the compilation of the base class of Y would be dependent on its derived class, since if Y derives from it, it would also be a friend of X, but if Y doesn't derive from it, it wouldn't be a friend of X. That's not possible.
Re: Friend declarations: nested classes and base-clauses
No, I didn't mean base class :P
base-clause = base-specifier = base-specifier-list
It's a place where we specify base classes which we want derived from.
Simply put:
Code:
class A : public BASE_CLASS_1, public BASE_CLASS_2 //<---- base-clause
{
//...
};