Condividi tramite


Errore del compilatore C2750

'type': impossibile usare 'new' nel tipo di riferimento; usare invece 'gcnew'

Per creare un'istanza di un tipo CLR, che fa sì che l'istanza venga inserita nell'heap di Garbage Collection, è necessario usare gcnew.

L'esempio seguente genera l'errore 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;
}