Compiler Error C2717
TOC
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

Compiler Error C2717

'__nogc new' cannot be used to create a managed type object

__nogc new can only be used to create instances of unmanaged classes and value types. For more information, see __nogc.

The following sample generates C2717:

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

__gc class G
{
};

int main()
{
   G* pG = __nogc new G;   // C2717
   // try the following line instead
   // G* pG = new G;

   G* arr __gc[] = __nogc new G*[10];   // C2717
   // try the following line instead
   // G* arr __gc[] = new G*[10];
}
Show:
© 2016 Microsoft