Share via


Compiler Error C2912

explicit specialization; 'declaration' is not a specialization of a function template

You cannot specialize a non-template function.

The following sample generates C2912:

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

This error will also be generated as a result of compiler conformance work that was done in Visual Studio .NET 2003: for every explicit specialization, you must choose the parameters of the explicit specialization, such that, they match the parameters of the primary template.

See Summary of Compile-Time Breaking Changes for more information.

// 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) {}
};