[comp.lang.c++] Scope of friendship

ecsv38@castle.ed.ac.uk (S Manoharan) (09/05/90)

Can a derived class automatically be a friend of a class whose 
friend is the base class?

class Z {
friend class Base;
private:
   int foo;
};

class Base {
private:
   Z bar;
public:
   void testB() { bar.foo = 1; }
};

class Derived : public Base {
private:
   Z bar;
public:
   void testD() { bar.foo = 1; }
};

Specifically, Base can access Z::foo; but, why shouldn't Derived
be permitted to access Z::foo?

Grrr! g++ (1.37.1) does not allow Z::foo to be accessed by Derived.

Thanks for your attention.

Manoharan.