CObArray::InsertAt
voidInsertAt(intnIndex**,CObject*newElement,intnCount=1);**
throw(CMemoryException);
voidInsertAt(intnStartIndex**,CObArray*pNewArray);**
throw(CMemoryException);
Parameters
nIndex
An integer index that may be greater than the value returned by GetUpperBound.
newElement
The CObject pointer to be placed in this array. A newElement of value NULL is allowed.
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
The first version of InsertAt inserts one element (or multiple copies of an element) at a specified index in an array. 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 CObArray collection, starting at the nStartIndex position.
The SetAt function, in contrast, replaces one specified array element and does not shift any elements.
The following table shows other member functions that are similar to CObArray::InsertAt.
Class | Member Function |
CByteArray | void InsertAt( int nIndex, BYTE newElement, int nCount=1 ); throw(CMemoryException); void InsertAt( int nStartIndex, CByteArray* pNewArray ); |
CDWordArray | void InsertAt( int nIndex, DWORD newElement, int nCount=1 ); throw(CMemoryException); void InsertAt( int nStartIndex, CDWordArray* pNewArray ); |
CPtrArray | void InsertAt( int nIndex, void* newElement, int nCount=1 ); throw(CMemoryException); void InsertAt( int nStartIndex, CPtrArray* pNewArray ); |
CStringArray | void InsertAt( int nIndex, LPCTSTR newElement, int nCount=1 ); throw(CMemoryException); void InsertAt( int nStartIndex, CStringArray* pNewArray ); |
CUIntArray | void InsertAt( int nIndex, UINT newElement, int nCount=1 ); throw(CMemoryException); void InsertAt( int nStartIndex, CUIntArray* pNewArray ); |
CWordArray | void InsertAt( int nIndex, WORD newElement, int nCount=1 ); throw(CMemoryException); void InsertAt( int nStartIndex, CWordArray* pNewArray ); |
Example
See CObList::CObList for a listing of the CAge
class used in all collection examples.
// example for CObArray::InsertAt
CObArray array;
array.Add( new CAge( 21 ) ); // Element 0
array.Add( new CAge( 40 ) ); // Element 1 (will become 2).
array.InsertAt( 1, new CAge( 30 ) ); // New element 1
#ifdef _DEBUG
afxDump.SetDepth( 1 );
afxDump << "InsertAt example: " << &array << "\n";
#endif
The results from this program are as follows:
InsertAt example: A CObArray with 3 elements
[0] = a CAge at $45C8 21
[1] = a CAge at $4646 30
[2] = a CAge at $4606 40
CObArray Overview | Class Members | Hierarchy Chart
See Also CObArray::SetAt, CObArray::RemoveAt