CArray::operator []

这些编写在下方的运算符是 SetAtGetAt 功能的便捷备用项。

TYPE& operator[]( 
   INT_PTR nIndex  
);
const TYPE& operator[]( 
   INT_PTR nIndex  
) const;

参数

  • 类型
    指定元素的类型模板参数中的数组。

  • nIndex
    将捕获的元素的索引。

备注

第一个运算符,调用对于不是 const的数组,在正确(r值)或左侧(左值)可以使用赋值语句。 第二,调用为 const 数组,则右边只能使用。

库的调试版本断言该下标(在赋值语句的左侧或右侧)是否在区域之外。

示例

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

请参见

参考

CArray选件类

层次结构图

CArray::GetAt

CArray::SetAt

CArray::ElementAt