This documentation is archived and is not being maintained.

Compiler Error C3185

Error Message

'typeid' used on managed type 'type', use 'operator' instead

You cannot apply the typeid operator to a managed type; use typeid instead.

The following sample generates C3185:

// C3185a.cpp
// compile with: /clr
ref class Base {};
ref class Derived : public Base {};

int main() {
   Derived ^ pd = gcnew Derived;
   Base ^pb = pd;
   const type_info & t1 = typeid(pb);   // C3185
   System::Type ^ MyType = Base::typeid;   // OK
};

Managed Extensions for C++

You cannot apply typeid to a managed type; use __typeof instead.

The following sample generates C3185:

// C3185b.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
__gc class Base {};
__gc class Derived : public Base {};

int main() {
   Derived *pd = new Derived;
   Base *pb = pd;
   const type_info & t1 = typeid(*pb);   // C3185

   // OK
   Type * t = __typeof(Base);
   Type * t1 = __typeof(Derived);
};
Show: