Export (0) Print
Expand All

23 The __typeof Keyword

Visual Studio .NET 2003

This built-in operation provides convenient syntactic access to the functionality of the System::Type::GetType() method. Whereas GetType() must be called on an object of the given type, __typeof() can take an abstract-declarator as an argument, and consequently does not require an object to be created.

Example

// mcpp_typeof.cpp
// compile with: /clr /LD
#using <mscorlib.dll>
using namespace System;
__gc struct G { int i; };

void f() {
   G *pG = new G;
   Type *pType = pG->GetType();   // GetType requires an object
   Type *pType2= __typeof(G);   // __typeof does not
}

Constraint

  • The argument to __typeof shall be managed type.
Show:
© 2015 Microsoft