Compiler Error C2750

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see Compiler Error C2750 on docs.microsoft.com. '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;  
}  

Show: