编译器错误 C2993

更新:2007 年 11 月

错误消息

“identifier”: 非类型模板参数“parameter”的类型非法

不能使用结构参数或联合参数声明模板。应使用指针将结构和联合作为模板参数来传递。

下面的示例生成 C2993:

// C2993.cpp
// compile with: /c
// C2993 expected
struct MyStruct {
   int a;char b;
};

template <class T, struct MyStruct S>   // C2993

// try the following line instead
// template <class T, struct MyStruct * S>
class CMyClass {};

也将由于在 Visual Studio .NET 2003 中进行的编译器一致性工作生成此错误:不再允许浮点非类型模板参数。C++ 标准不允许浮点非类型模板参数。

如果它是函数模板,则使用函数参数来传入浮点非类型模板参数(此代码将在 Visual C++ 的 Visual Studio .NET 2003 和 Visual Studio .NET 版本中有效)。如果它是类模板,则没有简单的变通方法。

有关更多信息,请参见编译时的重大更改摘要

// C2993b.cpp
// compile with: /c
template<class T, float f> void func(T) {}   // C2993

// OK
template<class T>   void func2(T, float) {}