CObArray::operator [ ]

CObject*& operator []( int nIndex );

CObject* operator []( int nIndex ) const;

Remarks

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

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 nIndex );
BYTE operator []( int
nIndex ) const;
CDWordArray DWORD& operator []( int nIndex );
DWORD operator []( int
nIndex ) const;
CPtrArray void*& operator []( int nIndex );
void* operator []( int
nIndex ) const;
CStringArray CString& operator []( int nIndex );
CString operator []( int
nIndex ) const;
CUIntArray UINT& operator []( int nIndex );
UINT operator []( int
nIndex ) const;
CWordArray WORD& operator []( int nIndex );
WORD operator []( int
nIndex ) const;

Example

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

// example for CObArray::operator []

CObArray array;
CAge* pa;

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

CObArray OverviewClass MembersHierarchy Chart

See Also   CObArray::GetAt, CObArray::SetAt