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

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.


// 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


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