編譯器錯誤 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
}
};