Export (0) Print
Expand All
Expand Minimize

Compiler Error C3162

Error Message

'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,

Example

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;
}

Community Additions

ADD
Show:
© 2015 Microsoft