我再程序中这样做
CArray<int,int> m_intCArray;
int nTest = 10;
m_intCArray.Add(nTest);
m_intCArray.RemoveAt(0,1);
m_intCArray.SetAt(0,nTest);
出错信息为
AFX_INLINE TYPE& CArray<TYPE, ARG_TYPE>::GetAt(INT_PTR nIndex)
{
ASSERT(nIndex >= 0 && nIndex < m_nSize);
if(nIndex >= 0 && nIndex < m_nSize)
return m_pData[nIndex];
AfxThrowInvalidArgException();
}
原因是RemoveAt的原理是:
CArray::RemoveAt
This method 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. It decrements the upper bound of the array but does not free memory.
我原本是不需要使用RemoveAt的啊。