#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();
} 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
  • 2021-08-02
  • 2022-12-23
  • 2021-08-14
猜你喜欢
  • 2022-12-23
  • 2021-09-04
  • 2021-05-31
  • 2021-08-08
  • 2021-12-08
相关资源
相似解决方案