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
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

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);
};

Community Additions

ADD
Show:
© 2015 Microsoft