CArray的RemoveAT

CArray使用详解
本文探讨了CArray在程序中的使用及遇到的问题,特别是RemoveAt方法的原理与注意事项,作者原本试图避免使用该方法但最终出现问题。

我再程序中这样做

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的啊。

转载于:https://www.cnblogs.com/WeRtogether/archive/2009/09/25/1574165.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值