共用方式為


HOW TO:宣告及使用內部指標和 Managed 陣列 (C++/CLI)

下列C++/CLI範例示範了如何宣告和使用陣列內部指標。

重要

此功能的語言支援的/clr編譯器選項,但非/ZW編譯器選項。

範例

3t2sye8x.collapse_all(zh-tw,VS.110).gif程式碼

// interior_ptr_arrays.cpp
// compile with: /clr
#define SIZE 10

int main() {
   // declare the array
   array<int>^ arr = gcnew array<int>(SIZE);

   // initialize the array
   for (int i = 0 ; i < SIZE ; i++)
      arr[i] = i + 1;

   // create an interior pointer into the array
   interior_ptr<int> ipi = &arr[0];

   System::Console::WriteLine("1st element in arr holds: {0}", arr[0]);
   System::Console::WriteLine("ipi points to memory address whose value is: {0}", *ipi);

   ipi++;
   System::Console::WriteLine("after incrementing ipi, it points to memory address whose value is: {0}", *ipi);
}

3t2sye8x.collapse_all(zh-tw,VS.110).gifOutput

1st element in arr holds: 1
ipi points to memory address whose value is: 1
after incrementing ipi, it points to memory address whose value is: 2

請參閱

參考

interior_ptr (C++/CLI)