Share via


CObArray::RemoveAt

voidRemoveAt(intnIndex**,intnCount=1);**

Parameters

nIndex

An integer index that is greater than or equal to 0 and less than or equal to the value returned by 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.

The following table shows other member functions that are similar to CObArray::RemoveAt.

Class Member Function
CByteArray void RemoveAt( int nIndex, int nCount = 1 );
CDWordArray void RemoveAt( int nIndex, int nCount = 1 );
CPtrArray void RemoveAt( int nIndex, int nCount = 1 );
CStringArray void RemoveAt( int nIndex, int nCount = 1 );
CUIntArray void RemoveAt( int nIndex, int nCount = 1 );
CWordArray void RemoveAt( int nIndex, int nCount = 1 );

Example

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

// example for CObArray::RemoveAt

   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

CObArray OverviewClass MembersHierarchy Chart

See Also   CObArray::SetAt, CObArray::SetAtGrow, CObArray::InsertAt