编译器错误 C2942
“class”:type-class-id 重新定义为函数的形参
不能将泛型或模板类用作形参。 不能直接将参数传递到泛型或模板类的构造函数。
此错误在 Visual Studio 2022 及更高版本中已过时。
下面的示例生成 C2942:
// C2942.cpp
// compile with: /c
template<class T>
struct TC {};
void f(int TC<int>) {} // C2942
// OK
struct TC2 {};
void f(TC2 i) {}
使用泛型时也可能发生 C2942:
// C2942b.cpp
// compile with: /clr /c
generic<class T>
ref struct GC {};
void f(int GC<int>) {} // C2942
ref struct GC2 { };
void f(int GC2) {}
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈