Visual C++ .NET/Class/Nested Class

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Add a Nested Class

 
#include "stdafx.h"
#using <mscorlib.dll>
using namespace System;
class Printer 
{ 
    class InkLevel; 
    friend class Printer::InkLevel;
    class PaperOutDetector; 
    friend class Printer:: PaperOutDetector;
}; 
class Printer::InkLevel
{ 
};

int main(void) {
  
}


Nested Class

 
#include "stdafx.h"
using namespace System;
ref class OutterClass
{
public:
   ref class NestedClass      // nested class
   {
   public:
      int publicMember;
   protected:
      int protectedMember;
   private:
      int privateMember;
   };
   NestedClass^ protectedNC;   // protected variable reference to NestedClass
private:
   NestedClass^ privateNC;     
public:
   NestedClass^ publicNC;      
   OutterClass() : publicNC(gcnew NestedClass),protectedNC(gcnew NestedClass),privateNC(gcnew NestedClass)
   {}
   void method()  
   {
      int x;
      NestedClass nc1;              
 
      x = nc1.publicMember;         
      x = publicNC->publicMember;   
      x = protectedNC->publicMember;
      x = privateNC->publicMember;  
   }
};
ref class inheritOutterClass : public OutterClass{
public:
   void method(){
      int x;
      NestedClass nc1;          
      x = nc1.publicMember;
      x = publicNC->publicMember;
      x = protectedNC->publicMember;
   }
};
void main()
{
   OutterClass sc;
   int x = sc.publicNC->publicMember;
}