编译器错误 C2912
显式专用化“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) {}
};
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈