Compiler Error C3257

Error Message

'object' : explicit call to ctor of __gc class type not allowed (did you forget 'new'?)

You cannot create temporary stack-based objects for managed classes. The compiler attempted to create a temporary object that is not directly mentioned in the code. This temporary object is created on the stack because there is no call to new.

C3257 is only reachable using /clr:oldSyntax.

The following sample generates C3257:

// C3257a.cpp
// compile with: /clr:oldSyntax /c
__gc class X {
   X(int i) {
      X();   // C3257
      X *MyX = new X();   // OK

Community Additions