CObArray::operator [ ]

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

CObject*& operator [](
   INT_PTR nIndex 
);
CObject* operator [](
   INT_PTR nIndex 
) const;

备注

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

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

下表显示类似于 **CObArray::operator []**的其他运算符。

运算符

CByteArray

BYTE& operator []( INT_PTRnIndex );

BYTE operator []( INT_PTR nIndex ) const;

CDWordArray

DWORD& operator []( INT_PTR nIndex );

DWORD operator []( INT_PTR nIndex ) const;

CPtrArray

void*& operator []( INT_PTR nIndex );

void* operator []( INT_PTR nIndex ) const;

CStringArray

CString& operator []( INT_PTR nIndex );

CString operator []( INT_PTR nIndex ) const;

CUIntArray

UINT& operator []( INT_PTR nIndex );

UINT operator []( INT_PTR nIndex ) const;

CWordArray

WORD& operator []( INT_PTR nIndex );

WORD operator []( INT_PTR nIndex ) const;

示例

提供用于所有集合示例的列表 CAge 选件类参见 CObList::CObList

CObArray arr;
CAge* pa;

arr.Add(new CAge(21)); // Element 0
arr.Add(new CAge(40)); // Element 1
pa = (CAge*)arr[0]; // Get element 0
ASSERT(*pa == CAge(21)); // Get element 0
arr[0] = new CAge(30); // Replace element 0
delete pa;
ASSERT(*(CAge*) arr[0] == CAge(30)); // Get new element 0      

要求

Header: afxcoll.h

请参见

参考

CObArray选件类

层次结构图

CObArray::GetAt

CObArray::SetAt