Interesting. This is a modified version of an example given in section 11.8 of the 2003 edition of the C++ Standard:
Code:
class E {
int x;
class B { };
class I {
B b; // error: E::B is private
int y;
void f(E* p, int i)
{
p->x = i; // error: E::x is private
}
};
int g(I* p)
{
//return p->y; // error: I::y is private
return 0;
}
};
int main(){}
The comments are given as in the text of the Standard, except that I commented out the line that the third comment comments on and added a return 0;
The above code compiles without warnings on the MinGW port of g++ 3.4.5 and the Comeau online compiler (both with C++0x extensions enabled and disabled). MSVC8 (from Visual Studio 2005) only gives a warning about an unused variable.
Consequently, it seems that according to the text of the current standard, all these compilers do not conform with respect to access control where nested classes are concerned. So, your book is right and these compilers are wrong (unless it is a defect in the Standard itself).