CObArray::RemoveAt
Removes one or more elements starting at a specified index in an array.
void RemoveAt(
INT_PTR nIndex,
INT_PTR nCount = 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
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 |
---|---|
void RemoveAt( INT_PTR nIndex, INT_PTR nCount = 1 ); |
|
void RemoveAt( INT_PTR nIndex, INT_PTR nCount = 1 ); |
|
void RemoveAt( INT_PTR nIndex, INT_PTR nCount = 1 ); |
|
void RemoveAt( INT_PTR nIndex, INT_PTR nCount = 1 ); |
|
void RemoveAt( INT_PTR nIndex, INT_PTR nCount = 1 ); |
|
void RemoveAt( INT_PTR nIndex, INT_PTR nCount = 1 ); |
Example
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
Requirements
Header: afxcoll.h