#include <iostream> #include <typeinfo> class Outer { private: class Inner { public: void Do() { std::cout<<"Do"<<std::endl; } }; private: Inner inner; public: Inner& Get() { return inner; } }; int main() { Outer O; // err: private Outer::Inner // Outer::Inner& x=O.Get(); x.Do(); auto& x=O.Get(); x.Do(); // ok std::cout << typeid(x).name() << std::endl; O.Get().Do(); // ok return 0; }