Export (0) Print
Expand All
Expand Minimize

Compiler Error C2842

'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 (C++/CLI).

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:
© 2014 Microsoft