Topic: What does "friend" forward declare?
Author: Thomas Holaday <tholaday>
Date: 1995/04/21 Raw View
sartin@pencom.com (Rob Sartin) wrote:
>class A {
> friend class B;
> class B {
> };
>};
>
>class B {
>};
>
>Which is the friend (::A::B or ::B)?
"If the identifier in the elaborated type specifier has not been previously
declared, the elaborated type specifier declares the identifier to be a
classname in the smallest enclosing nonclass, nonfunction prototype scope that
contains the declaration; otherwise the identifier is resolved as when the
elaborated type specifier is not the sole constituent of a declaration."
Thus, as written, B has not been previously declared, so friend class B refers
to ::B. If you want to befriend ::A::B, write:
class A {
class B ; // forward declaration of nested class
friend class B ; // now refers to A::B since it has been previously
declared
//...
};
--
~THol() Thomas Holaday
holaday_thomas@jpmorgan.com tlhol@ibm.net
70407.534@compuserve.com
Author: sartin@pencom.com (Rob Sartin)
Date: 1995/04/19 Raw View
In the declaration:
class A {
friend class B;
class B {
};
};
class B {
};
Which is the friend (::A::B or ::B)?
Two compilers I have tried seem to think the answer is ::B and that
matches my intuition and usage of "friend", but it is different
from how a "non-friend" forward declaration would work.
Regards,
Rob