编译器错误 C2921

重定义:“class”:类 template 或 generic 重新声明为“type”

generic 或 template 类具有多个不等效的声明。 要解决此错误,请对不同的类型使用不同的名称,或删除类型名称的重定义。

以下示例生成 C2921:

// C2921.cpp
// compile with: /c
template <class T> struct TC2 {};
typedef int TC2;   // C2921
// try the following line instead
// typedef struct TC2<int> x;   // OK - declare a template instance

使用 generic 时,也可能发生 C2921。

// C2921b.cpp
// compile with: /clr /c
generic <class T> ref struct GC2 {};
typedef int GC2;   // C2921
// try the following line instead
// typedef ref struct GC2<int> x;