CArray::InsertAt
The first version of InsertAt inserts one element (or multiple copies of an element) at a specified index in an array.
void InsertAt(
INT_PTR nIndex,
ARG_TYPE newElement,
INT_PTR nCount = 1
);
void InsertAt(
INT_PTR nStartIndex,
CArray* pNewArray
);
Parameters
nIndex
An integer index that may be greater than the value returned by GetUpperBound.ARG_TYPE
Template parameter specifying the type of elements in this array.newElement
The element to be placed in this array.nCount
The number of times this element should be inserted (defaults to 1).nStartIndex
An integer index that may be greater than the value returned by GetUpperBound.pNewArray
Another array that contains elements to be added to this array.
Remarks
In the process, it shifts up (by incrementing the index) the existing element at this index, and it shifts up all the elements above it.
The second version inserts all the elements from another CArray collection, starting at the nStartIndex position.
The SetAt function, in contrast, replaces one specified array element and does not shift any elements.
Example
// example for CArray::InsertAt
CArray<CPoint,CPoint> ptArray;
ptArray.Add(CPoint(10,20)); // Element 0
ptArray.Add(CPoint(30,40)); // Element 1 (will become element 2)
ptArray.InsertAt(1, CPoint(50,60)); // New element 1
Requirements
Header: afxtempl.h