This documentation is archived and is not being maintained.

Compiler Error C3255

'value type' : cannot dynamically allocate a value type object with managed members on C++ (nogc) heap

Instances of a __value type 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 <mscorlib.dll>
using namespace System;

__value struct V
{
   Object* o;
};

int main()
{
   V* pv = new V;   // C3255
   // try the following line instead
   V v2;

   DateTime dt = new DateTime(2001, 4, 12, 22, 16, 49, 844);   // C3255
   // try one of the following lines instead
   DateTime dt2 = DateTime(2001, 4, 12, 22, 16, 49, 844);   // ok
   DateTime dt3(2001, 4, 12, 22, 16, 49, 844);   // ok
}
Show: