上面的两个函数MSDN的例子使这样的
 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.
   }
他说只是删除掉一个成员;
我得实现是这样;
CObject *pOb;for(int i=0; i<m_arryLine.GetSize(); i++)
{
     pOb = m_arryLine.GetAt(i);
     if(pOb != NULL)
     {
m_arryLine.RemoveAt(i);
delete pOb;
pOb = NULL;
      }
}
程序运行时报告内存冲突我仅仅调用removeAt一次(实现和上面一样,仅仅少了for循环)从结果看,删除了两次我若去掉delete pOb运行正确;这样会不会有内存泄漏

解决方案 »

  1.   

    it shifts down all the elements above the removed element(s). 
    你每次m_arryLine.RemoveAt(i);
    i是变化的,移出一个之后元素,他后面的元素都会向前移动一个位置,i++之后需要删除的位置已经没东西了。
    m_arryLine.RemoveAt(i);直接改为m_arryLine.RemoveAt(0);也可以,i只用作计数。
      

  2.   

    CObject *pOb;for(int i=0; i<m_arryLine.GetSize(); i2B+)
    {
         pOb = m_arryLine.GetAt(i);
         if(pOb != NULL)
         {
    delete pOb;
          }
    }
    m_arryLine.RemoveAll();====