CObArray::SetAt

void SetAt( int nIndex, CObject* newElement );

参数:
nIndex一个整数索引值,它应大于或等于0,并小于或等于GetUpperBound的返回值。
newElement新插入到该数组的对象指针,允许为空值。

说明:
在指定索引处放置数组元素。SetAt函数将不导致数组增长。如果希望数组自动增长,请使用SetAtGrow函数。
必须确保索引值代表了数组中有效的位置。如果越界,那么将出现库调试版本的断言。
下表列出了类似于CObArray::SetAt函数的其它成员函数。
成员函数
CByteArrayvoid SetAt( int nIndex, BYTE newElement );
CDWordArrayvoid SetAt( int nIndex, DWORD newElement );
CPtrArrayvoid SetAt( int nIndex, void* newElement );
CStringArrayvoid SetAt( int nIndex, LPCTSTR newElement );
CUIntArrayvoid SetAt( int nIndex, UINT newElement );
CWordArrayvoid SetAt( int nIndex, WORD newElement );

示例:
请参阅CObList::CObList,了解所有收集示例中使用的CAge类。
// example for CObArray::SetAt
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.SetAt( 0, new CAge( 30 ) ); // Replace element 0.
  delete pa; // Delete the original element at 0.
}
#ifdef _DEBUG
   afxDump.SetDepth( 1 );
   afxDump << "SetAt example: " << &array << "\n";
#endif
该程序的结果如下:
SetAt example: A CObArray with 2 elements
[0] = a CAge at $47E0 30
[1] = a CAge at $47A0 40

请参阅:
CObArray::GetAt, CObArray::SetAtGrow, CObArray::ElementAt, CObArray::operator []