该法典有:
#include <iostream>
class Outer{
int a; // private data member of class Outer
public:
Outer(): a(55){}
class Inner{
public:
void fun(Outer ob){
std::cout << ob.a << std::endl;
}
};
};
int main() {
Outer::Inner object;
object.fun(Outer()); // prints 55
//std::cout << (Outer().a) << std::endl; error: int Outer::a is private
return 0;
}
Why Inner class has access to private member data a of class Outer? Following this article XL C/C++ V8.0 for Linux, it should not compile, however it compiles on g++ 4.4.0.