I have the following code where class A declares class B as friend. Should class C, declared within class B, be able to view private declarations/members of class A?
It compiles without error with CL version 16 (Visual Studio 2010), but gcc g++ version 4.1.1 gives the error "typedef int A::T is private within this context".
The same behaviour occurs with functions calls as typedefs (which is how I discovered the difference).
class A {
friend class B;
typedef int T;
};
class B {
A::T t; // ok
typedef A::T U; // ok
class C {
U u; // ok
A::T v; // compile error on gcc
};
};
I have seearched briefly, but not been able to find the right search terms. I've yet to read through the standard. Are there any previous questions on the subject, or mentioned in the C++ FAQ? Which behaviour is imlpied by the standard, if either?