We recommend using Visual Studio 2017

Compiler Error C3185

 

The latest version of this topic can be found at Compiler Error C3185.

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

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

The following sample generates C3185 and shows how to fix it:

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