This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Nested friend classes don't have access


// 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"




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]