Visual C++ .NET/Class/interior ptr
interior pointer
<source lang="csharp">
- include "stdafx.h"
using namespace System; ref struct MyStruct {
array<int>^ array1; MyStruct() { array1 = gcnew array<int>(10){ 0, 10, 20, 30, 40, 50, 60, 70, 80, 90 }; } void f() { interior_ptr<int> p = &array1[0]; for (int i = 0; i < 10; i++) { Console::WriteLine(*p++); } }
};
</source>
Using interior_ptr
<source lang="csharp">
- include "stdafx.h"
using namespace System; value class MyClass{
int i, j; public: void PrintStartingAddress() { interior_ptr<MyClass> ptr_to_this = this; pin_ptr<MyClass> pinned_this = ptr_to_this; Console::WriteLine("Starting address of object is 0x{0:x}",reinterpret_cast<int>(pinned_this)); }
}; int main() {
MyClass v; v.PrintStartingAddress();
}
</source>