Share via


typeid(C++ 구성 요소 확장)

개체 형식을 나타내는 값을 가져옵니다.

모든 런타임

kwd9abya.collapse_all(ko-kr,VS.110).gif구문

T::typeid

kwd9abya.collapse_all(ko-kr,VS.110).gif매개 변수

  • T
    형식 이름입니다.

Windows 런타임

kwd9abya.collapse_all(ko-kr,VS.110).gif구문

Platform::Type^ type = T::typeid;

kwd9abya.collapse_all(ko-kr,VS.110).gif매개 변수

  • T
    형식 이름입니다.

kwd9abya.collapse_all(ko-kr,VS.110).gif설명

C++/CX에서 typeid는 런타임 형식 정보에서 생성된 Platform::Type을 반환합니다.

kwd9abya.collapse_all(ko-kr,VS.110).gif요구 사항

컴파일러 옵션: /ZW

공용 언어 런타임

구문

type::typeid

매개 변수

  • type
    System::Type 개체에 적용할 형식의 이름(추상 선언자)입니다.

설명

typeid는 컴파일 시간에 형식에 대한 Type을 가져오는 데 사용됩니다.

typeid는 GetType 또는 GetType을 사용하여 런타임에 형식에 대해 System::Type을 가져오는 것과 비슷합니다.그러나 typeid는 형식 이름만 매개 변수로 받습니다.형식 인스턴스를 사용하여 System::Type 이름을 가져오려는 경우 GetType을 사용합니다.

typeid는 컴파일 시간에 형식 이름(type)을 평가할 수 있는 반면, GetType은 런타임에 반환할 형식을 평가할 수 있어야 합니다.

typeid는 네이티브 형식 이름 또는 네이티브 형식 이름에 대한 공용 언어 런타임 별칭을 사용할 수 있습니다. 자세한 내용은 C++ 네이티브 형식에 해당하는 .NET Framework(C++/CLI)을 참조하십시오.

typeid 역시 여전히 System::Type을 반환하기는 하지만 네이티브 형식에서 작동합니다.type_info 구조를 가려오려면 typeid 연산자를 사용합니다.

typeid는 이전 /clr 구문에서 __typeof의 후속 작업입니다.

kwd9abya.collapse_all(ko-kr,VS.110).gif요구 사항

컴파일러 옵션: /clr

kwd9abya.collapse_all(ko-kr,VS.110).gif예제

예제

다음 예제에서는 typeid 키워드를 GetType() 멤버와 비교합니다.

// keyword__typeid.cpp
// compile with: /clr
using namespace System;

ref struct G {
   int i;
};

int main() {
   G ^ pG = gcnew G;
   Type ^ pType = pG->GetType();
   Type ^ pType2 = G::typeid;

   if (pType == pType2)
      Console::WriteLine("typeid and GetType returned the same System::Type");
   Console::WriteLine(G::typeid);

   typedef float* FloatPtr;
   Console::WriteLine(FloatPtr::typeid);
}

Output

  
  

예제

다음 샘플에서는 형식 System::Type의 변수를 형식에 대한 특성을 가져오는 데 사용할 수 있음을 보여줍니다.또한 일부 형식의 경우 typedef를 만들어 typeid를 사용해야 함을 보여줍니다.

// keyword__typeid_2.cpp
// compile with: /clr
using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;

typedef int ^ handle_to_int;
typedef int * pointer_to_int;

public ref class MyClass {};

class MyClass2 {};

[attribute(AttributeTargets::All)]
ref class AtClass {
public:
   AtClass(Type ^) {
      Console::WriteLine("in AtClass Type ^ constructor");
   }
};

[attribute(AttributeTargets::All)]
ref class AtClass2 {
public:
   AtClass2() {
      Console::WriteLine("in AtClass2 constructor");
   }
};

// Apply the AtClass and AtClass2 attributes to class B
[AtClass(MyClass::typeid), AtClass2]   
[AttributeUsage(AttributeTargets::All)]
ref class B : Attribute {};

int main() {
   Type ^ MyType = B::typeid;

   Console::WriteLine(MyType->IsClass);
   
   array<Object^>^ MyArray = MyType -> GetCustomAttributes(true);
   for (int i = 0 ; i < MyArray->Length ; i++ )
      Console::WriteLine(MyArray[i]);

   if (int::typeid != pointer_to_int::typeid)
      Console::WriteLine("int::typeid != pointer_to_int::typeid, as expected");

   if (int::typeid == handle_to_int::typeid)
      Console::WriteLine("int::typeid == handle_to_int::typeid, as expected");
}

Output

  
  
  
  
  
  
  
  

참고 항목

개념

런타임 플랫폼의 구성 요소 확장