Partager via


CArray::operator

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

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

Parameters

  • TYPE
    Template parameter specifying the type of elements in this array.

  • nIndex
    Index of the element to be accessed.

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.

Example

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;
}

Requirements

Header: afxtempl.h

See Also

Reference

CArray Class

Hierarchy Chart

CArray::GetAt

CArray::SetAt

CArray::ElementAt