g++ compile such code without any warrnings: class C { private: class N { public: N(int val) { this->value = val; } int getValue() { return value; } private: int value; }; N nO; public: C() : nO(17) {} N &getNestedPrivateObject() { return nO; } };
int main() { C o; return o.getNestedPrivateObject().getValue(); } -- Summary: granted access to private nested class Product: gcc Version: 4.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dushistov at mail dot ru http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28539