Upraviť

Zdieľať cez


Compiler Error C2750

'type' : cannot use 'new' on the reference type; use 'gcnew' instead

To create an instance of a CLR type, which causes the instance to be placed on the garbage-collected heap, you must use gcnew.

The following sample generates C2750:

// C2750.cpp
// compile with: /clr
ref struct Y1 {};

int main() {
   Y1 ^ x = new Y1;   // C2750

   // try the following line instead
   Y1 ^ x2 = gcnew Y1;
}