Topic: friend class declaration and nested classes
Author: mkt@isun04.inf.uni-jena.de (Tilo Koerbs)
Date: 1996/02/07 Raw View
Consider this:
class X;
class Y {
class X {};
friend class ::X; // error!!!
};
I meet that nice problem when compiling the following code:
class A {
class B {};
friend class A::B; // error!!!
};
Most compilers compile this without a warning. Only the one from
DEC produced an 'invalid declarator' error.
I watched the ARM and found out:
Section 11.4: "... All the functions of a class X can be
made friends of a class Y by a single declaration
using an 'elaborated-type-specifier' ('9.1):
class Y {
friend class X;
// ...
};"
'elaborated-type-specifier':
'class-key' 'class-name'
'class-key' 'identifier'
enum 'enum-name'
'class-key':
class
struct
union
'class-name':
'identifier'
In what follows: The examples above are really errors!
Correcting the second example is easy:
class A {
class B {};
friend class B;
};
But how about the first example?!?!?!?
class X;
class Y {
class X {};
friend class X; // That's not what I want!
class X;
Or:
class X;
class Y {
friend class X; // Error: violating the rewriting rules!
class X {};
};
Bye.
Tilo Koerbs, mkt@uni-jena.de
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html. ]