CArray::operator []
這些註標運算子是 SetAt 和 GetAt 函式的便利替代。
TYPE& operator[](
INT_PTR nIndex
);
const TYPE& operator[](
INT_PTR nIndex
) const;
參數
型別
指定項目的型別樣板參數在這個中的陣列。nIndex
要存取之項目的索引。
備註
第一個運算子,為不是 const陣列,因此右 r (值) 或左邊 (左值) 可以使用指派陳述式。 第二,為 const 陣列,則只能使用。
程式庫的偵錯版本判斷此註標 (無論是在指派陳述式 (Assignment Statement) 的左邊或右邊) 是否超出界限。
範例
CArray<CPoint,CPoint> myArray;
// Add elements to the array.
for (int i = 0; i < 10; i++)
myArray.Add(CPoint(i, 2*i));
// Modify all the points in the array.
for (int i = 0; i <= myArray.GetUpperBound(); i++)
{
myArray[i].x = 0;
}
需求
Header: afxtempl.h