Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Compiler Error C3185
Collapse the table of content
Expand the table of content

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 (C++ Component Extensions) 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:
© 2015 Microsoft