Topic: friend declaration scope
Author: arthur@solomon.technet.sg (Arthur Sombrito)
Date: Wed, 7 Oct 1992 09:42:48 GMT Raw View
--
Hi,
I'd like to ask some rules regarding the scope of a friend declaration
which are not discussed (as far as I could tell) in the ARM.
Given the ff. code:
class B { protected : enum A {}; };
class C : public B {
friend class A; // According to the scoping rules, A refers to B::A.
// Since B::A is not a class, should we flag an error
// or do we declare a new class A since there is no
// existing type symbol in the scope of class C?
};
Thanks for any replies.
Author: arthur@solomon.technet.sg (Arthur Sombrito)
Date: Thu, 8 Oct 1992 07:20:51 GMT Raw View
--
Hi,
I'd like to add something to my original post.
One ambiguity is regarding the visibility and scope of a friend.
ARM p. 248 states that the name of a friend is not in the scope of
the class. I would assume that this refers to friend functions only.
Otherwise a nested class can't be made a friend.
ARM p. 250 states that an undeclared class or function name is
entered in the same scope as the name of the class containing
the friend declaration. It would then mean that if a nested class
exists with the same name as the friend class, then the friend class
refers to the nested class. Otherwise if no class exists by that
friend name, then it is a forward declaration of a class which is
in the same scope as the class containing the friend declaration.
Given:
short f() {}
class C { protected: enum A {}; class F {};};
class D {};
class F {};
class B : public C
{
long f() {}
friend short f(); // ok? Does it refer to ::f()?
friend class F; // ok - refers to C::F
friend class A; // ok - forward declare a ::A class
class D {};
friend class D; // Does it refer to B::D?
enum C {};
friend class C; // Is ::C visible?
// If my interpretation is correct, ::C is still
// visible since no class exists within class B
// definition
};
Many thanks.