编译器错误 C2912

更新:2007 年 11 月

错误消息

显式专用化;“declaration”不是函数模板的专用化

无法专用化非模板函数。

下面的示例生成 C2912:

// C2912.cpp
// compile with: /c
void f(char);
template<> void f(char);   // C2912
template<class T> void f(T);   // OK

在 Visual Studio .NET 2003 中执行编译器一致性工作时,也会生成此错误:对于每个显式专用化,必须选择显式专用化的参数,以使其与主模板的参数匹配。

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

// C2912b.cpp
class CF {
public:
   template <class A> CF(const A& a) {}   // primary template
   
   // attempted explicit specialization
   template <> CF(const char* p) {}   // C2912

   // try the following line instead
   // template <> CF(const char& p) {}
};