typeid(C++/CLI 및 C++/CX)

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

참고 항목

이 항목은 TypeId의 C++ 구성 요소 확장명 버전을 참조합니다. 이 키워드의 ISO C++ 버전은 typeid 연산자를 참조하세요.

모든 런타임

구문

T::typeid

매개 변수

T
형식 이름.

Windows 런타임

구문

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

매개 변수

T
형식 이름.

설명

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

요구 사항

컴파일러 옵션: /ZW

공용 언어 런타임

구문

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

매개 변수

type
System::Type 개체를 가져오려는 형식(추상 선언자)의 이름입니다.

설명

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

typeid 은 런타임에 System::Type 사용 GetType 하거나 GetType. 그러나 typeid 형식 이름만 매개 변수로 허용합니다. 형식의 인스턴스를 사용하여 이름을 System::Type 얻으려면 .를 사용합니다 GetType.

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

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

typeid 는 여전히 반환되지만 네이티브 형식에서도 작동합니다 System::Type. type_info 구조를 얻으려면 연산자를 사용합니다typeid.

요구 사항

컴파일러 옵션: /clr

예제

다음 예제에서는 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);
}
typeid and GetType returned the same System::Type
G

System.Single*

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

// 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");
}
True

in AtClass2 constructor

in AtClass Type ^ constructor

AtClass2

System.AttributeUsageAttribute

AtClass

int::typeid != pointer_to_int::typeid, as expected

int::typeid == handle_to_int::typeid, as expected

참고 항목

.NET 및 UWP용 구성 요소 확장