编译器错误 C2140

“type”:依赖于泛型类型参数的类型不允许作为编译器内部类型特征“trait”的参数

无效的类型说明符已传递给类型特征。

有关详细信息,请参阅编译器对类型特征的支持

示例

下面的示例生成 C2140。

// C2140.cpp
// compile with: /clr /c
template <class T>

struct is_polymorphic {
   static const bool value = __is_polymorphic(T);
};

class x {};

generic <class T>
ref class C {
   void f() {
      System::Console::WriteLine(__is_polymorphic(T));   // C2140
      System::Console::WriteLine(is_polymorphic<T>::value);   // C2140

      System::Console::WriteLine(__is_polymorphic(x));   // OK
      System::Console::WriteLine(is_polymorphic<x>::value);   // OK
   }
};