Export (0) Print
Expand All
Expand Minimize

Compiler Error C3841

illegal delete expression: managed type 'type' does not have a destructor defined

When compiled with /clr:oldSyntax, deleting a pointer only implements finalization. Therefore, if the class has no destructor defined (which implies that no Finalize method is provided), it is an error to delete a pointer to the type.

C3841 is only reachable using /clr:oldSyntax.

The following sample generates C3841:

// C3841.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
__gc class A
{   // implicitly derived from System::Object
public:
   ~A() {};
};

int main()
{
   System::Object* p = new A;
   delete p;   // C3841 since System::Object has no destructor defined
   A* q = static_cast<A*>(p);
   delete q;   // OK since A has a destructor
}

Community Additions

ADD
Show:
© 2014 Microsoft