This documentation is archived and is not being maintained.

Compiler Error C3840

Error Message

declaration of 'method' not allowed; use destructors to implement finalization

Declare a destructor instead of a Finalize method in a managed class.

C3840 is only reachable using /clr:oldSyntax.

The following sample generates C3840:

// C3840.cpp
// compile with: /clr:oldSyntax
#using <mscorlib.dll>
__gc class X

   void Finalize()
   {   // C3840, "declaration of 'X::Finalize' not allowed...

   // declare a destructor instead
   // ~X()
   // {
   // }

int main()