|
-
July 11th, 2010, 03:11 AM
#1
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:
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:
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...
-
July 11th, 2010, 04:53 AM
#2
Re: Friend declarations: nested classes and base-clauses
 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.
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
-
July 11th, 2010, 05:15 AM
#3
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
{
//...
};
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|