Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Compiler Error C2696

Cannot create a temporary object of a __gc type 'type'

References to const in an unmanaged program cause the compiler to call the constructor and create a temporary object on the stack. However, a managed __gc class can never be created on the stack.

The following sample generates C2696:

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

__gc class G 
   G( int i )

void func( const G& g );

int main()
   func( 1 );   // C2696
   // try the following line instead
   // G *myG = new G( 1 );
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft. All rights reserved.