#include<iostream> using namespace std; /* start of Enclosing class declaration */ class Enclosing { private: int x; /* start of Nested class declaration */ class Nested { public: int y; void NestedFun(Enclosing *e) { cout<<e->x; // works fine: nested class can access // private members of Enclosing class } }; // declaration Nested class ends here public: int access_nested(){ Nested nested; cout<<nested.y<<endl; return 0; } }; // declaration Enclosing class ends here int main() { Enclosing enclosing_instance; enclosing_instance.access_nested(); }