Compiler Error C2842
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Error C2842

Error Message

'class' : a managed type may not define its own 'operator new' or 'operator delete'

You can define your own operator new or operator delete to manage memory allocation on the native heap. However, reference classes cannot define these operators because they are only allocated on the managed heap.

For more information, see User-Defined Operators.

Example

The following sample generates C2842.

// C2842.cpp
// compile with: /clr /c
ref class G {
   void* operator new( size_t nSize );   // C2842
};

The following sample generates C2842.

// C2842_b.cpp
// compile with: /clr:oldSyntax /c
__gc class G {
   void* operator new( size_t nSize );   // C2842
};
Show:
© 2016 Microsoft