共用方式為


編譯器錯誤 C3225

'arg' 的泛型型別自變數不能是 'type',它必須是實值型別或句柄類型

備註

泛型類型自變數不是正確的類型。

如需詳細資訊,請參閱泛型

範例

您無法具現化具有原生類型的泛型型別。 下列範例會產生 C3225。

// C3225.cpp
// compile with: /clr
class A {};

ref class B {};

generic <class T>
ref class C {};

int main() {
   C<A>^ c = gcnew C<A>;   // C3225
   C<B^>^ c2 = gcnew C<B^>;   // OK
}

下列範例使用 C# 建立元件。 請注意,條件約束指定泛型型別只能使用實值型別具現化。

// C3225_b.cs
// compile with: /target:library
// a C# program
public class MyList<T> where T: struct {}

此範例會使用 C# 撰寫的元件,並違反了 MyList 僅能以非 Nullable 以外的值類型進行實例化的限制。 下列範例會產生 C3225。

// C3225_c.cpp
// compile with: /clr
#using "C3225_b.dll"
ref class A {};
value class B {};
int main() {
   MyList<A> x;   // C3225
   MyList<B> y;   // OK
}