You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to: Declare Pinning Pointers and Value Types | Microsoft Docs
ms.custom
ms.date
11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-windows
ms.tgt_pltfrm
ms.topic
language-reference
dev_langs
C++
helpviewer_keywords
value types, declaring
pinning pointers
ms.assetid
57c5ec8a-f85a-48c4-ba8b-a81268bcede0
caps.latest.revision
8
author
mikeblome
ms.author
mblome
manager
ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw
How to: Declare Pinning Pointers and Value Types
A value type can be implicitly boxed. You can then declare a pinning pointer to the value type object itself and use a pin_ptr to the boxed value type.
Example
Code
// pin_ptr_value.cpp
// compile with: /clr
value struct V {
int i;
};
int main() {
V ^ v = gcnew V; // imnplicit boxing
v->i=8;
System::Console::WriteLine(v->i);
pin_ptr<V> mv = &*v;
mv->i = 7;
System::Console::WriteLine(v->i);
System::Console::WriteLine(mv->i);
}