This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: nested class as friend
- To: Luc Claeys <claeys at innet dot be>
- Subject: Re: nested class as friend
- From: Alexandre Oliva <oliva at dcc dot unicamp dot br>
- Date: 31 Oct 1997 12:11:42 -0200
- Cc: egcs-bugs at cygnus dot com
- References: <199710301832.TAA15914@gandalf.home>
Luc Claeys writes:
> I want to make a nested class Y::Z a friend of class A.
Then the definition of class Y must have been provided already, and it
must contain at leat a declaration of nested class Z:
class Y {
class Z;
// ...
};
class A {
friend class Y::Z;
// ...
};
class Y::Z {
// ...
};
Your example 3:
> class Y;
> class Z; // not true, but is a workaround for gcc 2.7.2
because gcc 2.7.2 is buggy.
> class A {
> friend class Y::Z;
> };
> -----------^-------
>> g++ -c -Wall tst1.cc
> tst1.cc:5: `Y' does not have a nested type named `Z'
maybe egcs should say that Y is not completely defined yet...
> This last version would be fine as long class Y is the only
> class with a subclass Z (ARM Section 18.3.5 p407).
Nope, it would only be ok if Y were completely defined, and known to
have a nested type Z.
> I could even say
> friend class Z;
Only if Z were really a global class.
> However with subclasses like "iterator", many classes have
> a subclass with the name "iterator", we should not make them
> all friends.
I assume wherever you refer to `subclass', you mean `nested class'. A
subclass is a completely different animal :-)
In fact, you can't, as there can be at most a single class named
`iterator' in a namespace.
--
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil