Export (0) Print
Expand All
Expand Minimize

Compiler Error C2910

Error Message

'function' : cannot be explicitly specialized

The compiler detected an attempt to explicitly specialize a function twice.

The following sample generates C2910:

// C2910.cpp
// compile with: /c
template <class T>
struct S;

template <> struct S<int> { void f() {} };
template <> void S<int>::f() {}   // C2910 delete this specialization

C2910 can also be generated if you try to explicitly specialize a non-template member. That is, you can only explicitly specialize a function template.

The following sample generates C2910:

// C2910b.cpp
// compile with: /c
template <class T> struct A {
   A(T* p);
};

template <> struct A<void> {
   A(void* p);
};

template <class T>
inline A<T>::A(T* p) {}

template <> A<void>::A(void* p){}   // C2910
// try the following line instead
// A<void>::A(void* p){}

This error will also be generated as a result of compiler conformance work that was done in Visual Studio .NET 2003:.

For code will be valid in the Visual Studio .NET 2003 and Visual Studio .NET versions of Visual C++, remove template <>.

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

The following sample generates C2910:

// C2910c.cpp
// compile with: /c
template <class T> class A {
   void f();
};

template <> class A<int> {
   void f();
};

template <> void A<int>::f() {}   // C2910
// try the following line instead
// void A<int>::f(){}   // OK

Community Additions

ADD
Show:
© 2014 Microsoft