编译器错误 C3227
“parameter”:不能使用“keyword”来分配泛型类型
为了实例化类型,需要适当的构造函数。 但是,编译器无法确保适当的构造函数可用。
可以使用模板而不是泛型来解决此错误,也可以使用多种方法之一来创建该类型的实例。
示例
以下示例生成 C3227。
// C3227.cpp
// compile with: /clr /c
generic<class T> interface class ICreate {
static T Create();
};
generic <class T>
where T : ICreate<T>
ref class C {
void f() {
T t = new T; // C3227
// OK
T t2 = ICreate<T>::Create();
T t3 = safe_cast<T>( System::Activator::CreateInstance(T::typeid) );
}
};