Compiler Error C2897

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

a destructor/finalizer cannot be a function template

Destructors or finalizers cannot be overloaded, so declaring a destructor as a template (which would define a set of destructors) is not allowed.

The following sample generates C2897:

The following sample generates C2897.

// C2897.cpp  
// compile with: /c  
class X {  
public:  
   template<typename T> ~X() {}   // C2897  
};  

The following sample generates C2897.

// C2897_b.cpp  
// compile with: /c /clr  
ref struct R2 {  
protected:  
   template<typename T> !R2(){}   // C2897 error  
};  

Show: