This documentation is archived and is not being maintained.

Compiler Error C2726

'__gc new' cannot be used to create a non-gc type object

You cannot create a managed instance of an unmanaged class.

The following sample generates C2726:

// C2726.cpp
// compile with: /clr
#using <mscorlib.dll>
using namespace System;

class U
{
};

int main()
{
   U* pU = __gc new U;    // C2726
   // try the following line instead
   // U* pU = new U;
   // or declare the class as follows
   // __gc class U
}
Show: