Share via


编译器错误 C2179

“type”:特性参数不能使用类型参数

泛型类型参数在运行时解析。 但是,必须在编译时解析属性参数。 因此,你不能将泛型类型参数用作属性的参数。

示例

以下示例生成 C2179。

// C2179.cpp
// compile with: /clr
using namespace System;

public ref struct Attr : Attribute {
   Attr(Type ^ a) {
      x = a;
   }

   Type ^ x;
};

ref struct G {};

generic<typename T>
public ref class Z {
public:
   Type ^ d;
   [Attr(T::typeid)]   // C2179
   // try the following line instead
   // [Attr(G::typeid)]
   T t;
};