Compiler Error C3162

 

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

'type' : a reference type which has a destructor cannot be used as the type of static data member 'member'

The common language runtime cannot know when to run a user-defined destructor when the class also contains static member function.

A destructor will never be run unless the object is deleted explicitly.

For more information, see,

The following sample generates C3162.

// C3162.cpp  
// compile with: /clr /c  
ref struct A {  
   ~A() { System::Console::WriteLine("in destructor"); }  
   static A i;   // C3162  
   static A^ a = gcnew A;   // OK  
};  
  
int main() {  
   A ^ a = gcnew A;  
   delete a;  
}  

Show: