CObArray::RemoveAt

Syntax

void RemoveAt( int nIndex, int nCount = 1 );

Parameters

nIndex

An integer index that is greater than or equal to 0 and less than or equal to GetUpperBound().

nCount

The number of elements to remove.

Remarks

Removes one or more elements starting at a specified index in an array. In the process, it shifts down all the elements above the removed element(s). It decrements the upper bound of the array but does not free memory.

If you try to remove more elements than are contained in the array above the removal point, then the Debug version of the library asserts.

The RemoveAt function removes the CObject pointer from the array, but it does not delete the object itself.

Example

CObArray array;

CObject* pa;

array.Add( new CAge( 21 ) ); // Element 0

array.Add( new CAge( 40 ) ); // Element 1

if( ( pa = array.GetAt( 0 ) ) != NULL )

{

array.RemoveAt( 0 ); // Element 1 moves to 0

delete pa; // Delete the original element at 0

}

#ifdef _DEBUG

afxDump.SetDepth( 1 );

afxDump << "RemoveAt example: " << &array << "\\n";

#endif

The results from this program are as follows:

RemoveAt example: A CObArray with 1 elements

[0] = a CAge at $4606 40

See Also

CObArray::SetAt, CObArray::SetAtGrow, CObArray::InsertAt