Export (0) Print
Expand All
Expand Minimize

Compiler Error C3255

Error Message

'value type' : cannot dynamically allocate this value type object on native heap

Instances of a value type (see Classes and Structs (Managed)) that contain managed members can be created on the stack but not on the heap.

The following sample generates C3255:

// C3255.cpp
// compile with: /clr
using namespace System;
value struct V {
   Object^ o;
};

value struct V2 {
   int i;
};

int main() {
   V* pv = new V;   // C3255
   V2* pv2 = new V2;
   V v2;
}

Managed Extensions for C++

The following sample generates C3255:

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

__value struct V {
   Object* o;
};

__value struct V2 {
   int i;
};

int main() {
   V* pv = __nogc new V;   // C3255
   V2* pv2 = __nogc new V2;   // OK
}

Community Additions

ADD
Show:
© 2015 Microsoft