468,777 Members | 2,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,777 developers. It's quick & easy.

friend sibling class nested in derived class problem in gcc 4.0

Hi all,
I'm in doubt with the following code:

class Base {
class Nested {};
class Derived:public Base {
class Nested {
void m();
class AnotherNested {
friend class Nested; // gcc 4.0.2 takes it as 'Base::Nested'
//friend class Derived::Nested; // this is needed in order to
be compiled by gcc 4.0.2
#line 14
AnotherNested() {}
void Derived::Nested::m() {
#line 18
Derived::AnotherNested instance;

should the first friend decl refer to Base::Nested or Derived::Nested?

The code is refused e.g. by gcc 4.0(.0,.2):
a.cpp: In member function 'void Derived::Nested::m()':
a.cpp:14: error: 'Derived::AnotherNested::AnotherNested()' is private
a.cpp:18: error: within this context
because gcc 4 takes for granted the friend refers to Base::Nested.
However, e.g. gcc 3.4 takes it as Derived::Nested.
Declaring the friend the second way:
friend class Derived::Nested;
works in gcc 4.0, but I see two issues with it:
1) it uses not-yet-fully-declared class Derived
2) some compilers (e.g. VC 6.0) can't compile it (because of the
Derived incompletness)

I've not succeeded tracking this issue neither in the C++ standard nor
in gcc.
best regards
Tomas Sieger

Dec 16 '05 #1
1 1893
FYI: this has been confirmed as bug in gcc:
Tomas Sieger

Dec 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Charles Jamieson | last post: by
8 posts views Thread by Mike C# | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
2 posts views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.