Expand Minimize
0 out of 1 rated this helpful - Rate this topic

Compiler Error C3841

Error Message

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
}
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.