Compiler Error C2750
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at 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;
}
Show: