Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All


Note   This topic applies only to version 1 of Managed Extensions for C++. This syntax should only be used to maintain version 1 code. See typeid for information on using the equivalent functionality in the new syntax.

Returns the System::Type of a specified type.




The name of a managed type for which you want the System::Type name. Note that in a managed program, some native types are aliased to types in the common language runtime. For example, int is an alias for System::Int32.

The __typeof operator lets you get the System::Type type of a type that you specify. __typeof can also be used to return a value of System::Type in a custom attribute block. See attribute for more information about creating your own attributes.

In the following example, a custom attribute (AtClass) is applied to a __gc class (B). The value of the custom attribute is then retrieved with __typeof:

// keyword__typeof.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
using namespace System;

public __gc class MyClass {};

__gc class AtClass {
   AtClass(Type*) {
      Console::WriteLine("in Type * constructor");

   AtClass(String*) {}
   AtClass(int) {}

[AtClass(__typeof(MyClass))]   // Apply AtClass attribute to class B
__gc class B {};

int main() {
   Type * mytype = __typeof(B);
   Object * myobject __gc[] = mytype -> GetCustomAttributes(true);

in Type * constructor

Community Additions

© 2015 Microsoft