This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Nested friend classes don't have access
- To: <egcs-bugs at cygnus dot com>
- Subject: Nested friend classes don't have access
- From: "Bruce Eckel" <Bruce at EckelObjects dot com>
- Date: Tue, 12 Jan 1999 06:27:05 -0800
- Reply-To: "Bruce Eckel" <Bruce at EckelObjects dot com>
// i586-pc-linux-gnu
// gcc version egcs-2.92.34 19990103 (gcc2 ss-980609 experimental) reports:
// friendclass.cpp: In method `int C::D::f()':
// friendclass.cpp:40: member `i' is a private member of class `C'
#include <iostream>
using namespace std;
// This works:
class A {
int i;
public:
A(int ii) : i(ii) {}
friend class B;
};
class B {
A* a;
public:
B(A* aa) : a(aa) {}
int f() { return a->i; }
};
void f1() {
A a(1);
B b(&a);
cout << b.f() << endl;
}
// Shouldn't this compile?:
class C {
int i;
public:
C(int ii) : i(ii), d(this) {}
friend class D;
class D {
C* c;
public:
D(C* cc) : c(cc) {}
int f() { return c->i; }
} d;
};
void f2() {
C c(1);
cout << c.d.f() << endl;
}
int main() {
f1();
f2();
}
=============================
Bruce Eckel http://www.BruceEckel.com
Contains free electronic books: "Thinking in Java" & "Thinking in C++ 2e"