__typeof (C++)

Switch View :
ScriptFree
Managed Extensions for C++ Reference
__typeof

Returns the System::Type of a specified type.

__typeof(typename)

where:

typename
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.

Remarks

The __typeof operator lets you get the System::Type type of a type that you specify. For more information on __typeof, see 23 The __typeof Keyword. __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.

For more information on types in the common language runtime, see Introduction to the .NET Framework Class Library.

Example

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
#using <mscorlib.dll>
using namespace System;

public __gc class MyClass {};

[attribute(All)]
__gc class AtClass 
{
public:
   AtClass(Type*) 
   {
      Console::WriteLine("in Type * constructor");
   }

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

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

int main()
{
   Type * mytype = __typeof(B);
   Object * myobject __gc[] = mytype -> GetCustomAttributes(true);
   Console::WriteLine(myobject[0]);
   return 0;
}

Output

in Type * constructor
AtClass

See Also

Managed Extensions for C++ Reference | Introduction to .NET framework