编译器错误 C2974

无效的类型参数“number”,类型应为

泛型或模板参数与泛型或模板声明不匹配。 类型应放在尖括号内。 请检查泛型或模板定义,以找到正确的类型。

下面的示例生成 C2974:

// C2974.cpp
// C2974 expected
template <class T>
struct TC {};

template <typename T>
void tf(T){}

int main() {
   // Delete the following 2 lines to resolve
   TC<1>* tc;
   tf<"abc">("abc");

   TC<int>* tc;
   tf<const char *>("abc");
}

在使用泛型时,也可能出现 C2974:

// C2974b.cpp
// compile with: /clr
// C2974 expected
using namespace System;
generic <class T>
ref struct GCtype {};

generic <typename T>
void gf(T){}

int main() {
   // Delete the following 2 lines to resolve
   GCtype<"a">^ gc;
   gf<"a">("abc");

   // OK
   GCtype<int>^ gc;
   gf<String ^>("abc");
}