CObArray::InsertAt

void InsertAt( int nIndex, CObject* newElement, int nCount = 1 );
  throw( CMemoryException );
void InsertAt( int nStartIndex, CObArray* pNewArray );
  throw( CMemoryException );

参数:
nIndex可以比GetUpperBound返回值大的整数索引。
newElement该数组中被安置的CObject指针。newElement值允许为NULL。
nCount该元素被插入的次数(缺省值为1)。
nStartIndex可以比GetUpperBound返回值大的整数索引。
pNewArray包含添加到该数组元素的另一个数组。

说明:
第一版本InsertAt在数组指定索引处插入一个元素(或该元素的多个拷贝)。在该过程中,它将依次增加该索引及该索引以上的元素索引值(按照索引的增量)。
第二版本则在nStartIndex位置插入另一个CObArray集合中的所有元素。
相反的是,SetAt函数将替换指定的数组元素,但不移动其它元素。
下表列出了类似于CObArray::InsertAt函数的其它成员函数。
成员函数
CByteArrayvoid InsertAt( int nIndex, BYTE newElement, int nCount= 1 );
  throw( CMemoryException );
void InsertAt( int nStartIndex, CByteArray* pNewArray );
  throw( CMemoryException );
CDWordArrayvoid InsertAt( int nIndex, DWORD newElement, int nCount = 1 );
  throw( CMemoryException );
void InsertAt( int nStartIndex, CDWordArray*pNewArray );
  throw( CMemoryException );
CPtrArrayvoid InsertAt( int nIndex, void* newElement, int nCount = 1 );
  throw( CMemoryException );
void InsertAt( int nStartIndex, CPtrArray* pNewArray );
  throw( CMemoryException );
CStringArrayvoid InsertAt( int nIndex, LPCTSTR newElement, int nCount = 1 );
  throw( CMemoryException );
void InsertAt(int nStartIndex, CStringArray* pNewArray);
  throw( CMemoryException);
CUIntArrayvoid InsertAt(int nIndex,UINT newElement,int nCount =1);
  throw( CMemoryException);
void InsertAt( int nStartIndex, CUIntArray* pNewArray);
  throw( CMemoryException);
CWordArrayvoid InsertAt(int nIndex,WORD newElement,int nCount= 1);
  throw( CMemoryException);
void InsertAt(int nStartIndex, CwordArray* pNewArray);
  throw( CMemoryException);

示例:
请参阅CObList::CObList,了解所有收集示例中使用的CAge类。
// example for CObArray::InsertAt
CObArray array;
array.Add( new CAge( 21 ) ); // Element 0
array.Add( new CAge( 40 ) ); // Element 1 (will become 2).
array.InsertAt( 1, new CAge( 30 ) ); // New element 1
#ifdef _DEBUG
   afxDump.SetDepth( 1 );
   afxDump << "InsertAt example: " << &array << "\n";
#endif
该程序的结果如下:
InsertAt example: A CObArray with 3 elements
[0] = a CAge at $45C8 21
[1] = a CAge at $4646 30
[2] = a CAge at $4606 40

请参阅:CObArray::SetAt, CObArray::RemoveAt