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: Declare Pinning Pointers and Value Types | Microsoft Docs |
11/04/2016 |
|
language-reference |
|
|
57c5ec8a-f85a-48c4-ba8b-a81268bcede0 |
8 |
mikeblome |
mblome |
ghogen |
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.
// 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);
}
8
7
7