编译器错误 C3185

在托管或 WinRT 类型“type”上使用了“typeid”,请改用“operator”

无法将 typeid 运算符应用于托管或 WinRT 类型;请改用 typeid

下面的示例生成 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
};