This topic has not yet been rated - Rate this topic

CObArray::RemoveAt

Removes one or more elements starting at a specified index in an array.

void RemoveAt( 
   INT_PTR nIndex, 
   INT_PTR nCount = 1  
);
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.

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_PTR nIndex , INT_PTR nCount = 1 );

CDWordArray

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

CPtrArray

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

CStringArray

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

CUIntArray

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

CWordArray

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

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

CObArray arr;
CObject* pa;

arr.Add(new CAge(21)); // Element 0
arr.Add(new CAge(40)); // Element 1 
if((pa = arr.GetAt(0)) != NULL)
{
    arr.RemoveAt(0);  // Element 1 moves to 0. 
    delete pa; // Delete the original element at 0.
}
#ifdef _DEBUG
   afxDump.SetDepth(1);
   afxDump << _T("RemoveAt example: ") << &arr << _T("\n");
#endif      

The results from this program are as follows:

RemoveAt example: A CObArray with 1 elements

[0] = a CAge at $4606 40

Header: afxcoll.h

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.