Compiler Error C2765

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at Compiler Error C2765.

function' : an explicit specialization of a function template cannot have any default arguments

Default arguments are not allowed on an explicit specialization of a function template. For more information, see Explicit Specialization of Function Templates.

The following sample generates C2765:

// C2765.cpp  
template<class T> void f(T t) {};  
  
template<> void f<char>(char c = 'a') {}   // C2765  
// try the following line instead  
// template<> void f<char>(char c) {}  

Show: