Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Use gcnew to Create Value Types and Use Implicit Boxing

Using gcnew on a value type will create a boxed value type, which can then be placed on the managed, garbage-collected heap.


// vcmcppv2_explicit_boxing4.cpp
// compile with: /clr
public value class V {
   int m_i;
   V(int i) : m_i(i) {}

public ref struct TC {
   void do_test(V^ v) {
      if (v != nullptr)

int main() {
   V^ v = gcnew V(42);
   TC^ tc = gcnew TC;

See Also

Community Additions

© 2015 Microsoft