Thread View: comp.std.c++
2 messages
2 total messages
Started by Tilo Koerbs
Wed, 07 Feb 1996 19:35
friend class declaration and nested classes
Author: Tilo Koerbs
Date: Wed, 07 Feb 1996 19:35
Date: Wed, 07 Feb 1996 19:35
74 lines
2154 bytes
2154 bytes
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. ]
Re: friend class declaration and nested classe
Author: Steve Clamage
Date: Wed, 07 Feb 1996 22:00
Date: Wed, 07 Feb 1996 22:00
53 lines
1847 bytes
1847 bytes
In article 1rp@fsuj01.rz.uni-jena.de, mkt@isun04.inf.uni-jena.de (Tilo Koerbs) writes:
> class X;
> class Y {
> class X {};
> friend class ::X; // error!!!
> };
No, that example is OK.
>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'
The grammar in the ARM is not quite complete or correct. The draft standard says
elaborated-type-specifier:
class-key ::[opt] nested-name-specifier[opt] identifier
enum ::[opt] nested-name-specifier[opt] identifier
So things like
friend class ::X;
friend class A::B::X;
are allowed by the syntax.
---
Steve Clamage, stephen.clamage@eng.sun.com
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy is
summarized in http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads