Condividi tramite


CObArray::operator

These subscript operators are a convenient substitute for the SetAt and GetAt functions.

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

Remarks

The first operator, called for arrays that are not const, may be used on either the right (r-value) or the left (l-value) of an assignment statement. The second, called for const arrays, may be used only on the right.

The Debug version of the library asserts if the subscript (either on the left or right side of an assignment statement) is out of bounds.

The following table shows other operators that are similar to CObArray::operator [].

Class

Operator

CByteArray

BYTE& operator []( INT_PTR nIndex );

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;

Example

See CObList::CObList for a listing of the CAge class used in all collection examples.

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      

Requirements

Header: afxcoll.h

See Also

Reference

CObArray Class

Hierarchy Chart

CObArray::GetAt

CObArray::SetAt

Other Resources

CObArray Members