Skip to content

Latest commit

 

History

History
49 lines (44 loc) · 1.18 KB

how-to-use-gcnew-to-create-value-types-and-use-implicit-boxing.md

File metadata and controls

49 lines (44 loc) · 1.18 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
How to: Use gcnew to Create Value Types and Use Implicit Boxing | Microsoft Docs
11/04/2016
cpp-windows
article
C++
gcnew keyword [C++], creating value types
boxing, implicit
value types, creating
ceb48841-d6bd-47be-a167-57f44c961603
8
mikeblome
mblome
ghogen

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.

Example

// vcmcppv2_explicit_boxing4.cpp  
// compile with: /clr  
public value class V {  
public:  
   int m_i;  
   V(int i) : m_i(i) {}  
};  
  
public ref struct TC {  
   void do_test(V^ v) {  
      if (v != nullptr)  
         ;  
      else  
         ;  
   }  
};  
  
int main() {  
   V^ v = gcnew V(42);  
   TC^ tc = gcnew TC;  
   tc->do_test(v);  
}  

See Also

Boxing