编译器错误 C2940

“class”:type-class-id 已重新定义为局部 typedef

不能将泛型或模板类用作局部 typedef

此错误在 Visual Studio 2022 及更高版本中已过时。

以下示例生成 C2940:

// C2940.cpp
template<class T>
struct TC {};
int main() {
   typedef int TC<int>;   // C2940
   typedef int TC;   // OK
}

使用泛型时,也可能发生 C2940:

// C2940b.cpp
// compile with: /clr
generic<class T>
ref struct GC { };

int main() {
   typedef int GC<int>;   // C2940
   typedef int GC;
}