중첩된 형식 이름

Microsoft C++ 지원 중첩 형식의 선언을-명명 된 형식과 익명 합니다.익명 구조체 및 클래스 C++ Microsoft 특정 확장입니다.익명 공용 구조체는 표준입니다.

[::] class-name :: class-name
[::] template-id :: class-name
[::] class-name :: template-id
[::] template-id :: template template-id
:: template template-id :: template template-id

설명

1 종-이름 위의 외부 클래스를 나타냅니다. 두 번째는 내부 클래스를 참조합니다.이러한 이름은 더 이상 중첩할 수 있습니다.따라서,

Outer::Inner
::Outer::Inner
::Outer::Inner::Inner2

모든 유효한 클래스 이름입니다.클래스 이름 대신 템플릿 식별자, 템플릿은 선택적 키워드를 사용 하는 사용 될 수 있습니다.

MyClass<int>::Inner
Outer<int>::template Inner<int>

경우에 따라 프로그래밍 하면 중첩 된 형식을 정의 하는 것이 있습니다.이러한 형식에 정의 된 클래스 형식의 멤버 함수에만 나타납니다.이들은 또한 범위 결정 연산자를 사용 하 여 정규화 된 형식 이름을 구성 하 여 표시할 수 있습니다 (::).

[!참고]

중첩된 형식을 사용 하는 하나 널리 사용 되는 클래스 계층 구조 iostream입니다.Iostream 헤더 파일의 클래스 정의에서 io 일련의 iostream 라이브러리 에서만 사용할 패키지 된 열거 형식에 포함 되어 있습니다.

예제

다음 예제에서는 중첩 된 클래스를 정의합니다.

// nested_type_names1.cpp
class WinSystem
{
public:
   class Window
   {
   public:
      Window();   // Default constructor.
      ~Window();   // Destructor.
      int NumberOf();   // Number of objects of class.        
      int Count();   // Count number of objects of class.
   private:
      static int CCount;
   };

   class CommPort
   {
   public:
      CommPort();   // Default constructor.
      ~CommPort();   // Destructor.
      int NumberOf();   // Number of objects of class.
      int Count();   // Count number of objects of class.
   private:
      static int CCount;
   };
};

// Initialize WinSystem static members.
int WinSystem::Window::CCount = 0;
int WinSystem::CommPort::CCount = 0;

int main()
{
}

중첩 된 클래스에 정의 된 이름에 액세스 하려면 범위 결정 연산자를 사용 합니다. (::) 전체 클래스 이름을 생성 합니다.이 연산자의 사용의 초기화에 표시 되는 정적 앞의 예제에서 멤버.프로그램에서 중첩 된 클래스를 사용 하려면 다음과 같은 코드를 사용 합니다.

WinSystem::Window Desktop;
WinSystem::Window AppWindow;

cout << "Number of active windows: " << Desktop.Count() << "\n";

중첩 된 익명 클래스 또는 구조체 이름으로 정의할 수 있습니다.

// nested_type_names2.cpp
class Ledger
{
   class
   {
   public:
      double PayableAmt;
      unsigned PayableDays;
   } Payables;

   class
   {
   public:
      double RecvableAmt;
      unsigned RecvableDays;
   } Receivables;
};

int main()
{
}

익명 클래스 멤버 함수와 정적 멤버가 있는 집계 해야 합니다.

특정 최종 Microsoft

[!참고]

열거 형식을 클래스 선언 안에 정의할 수 있지만 반대의 true 아닙니다. 클래스 형식은 열거형 선언은 정의할 수 없습니다.

참고 항목

참조

C + +의 형식 지정자