CObList::SetAt

void SetAt( POSITION pos, CObject* newElement );

参数:
pos元素所要设定的POSITION值。
newElement要写入列表的CObject指针。

说明:
一个类型为 POSITION 的变量是列表的一个键值。不同于索引的是, 不能对POSITION 值执行操作。 SetAt 将把给定的CObject 指针写到列表中的指定位置。
必须确保所给的POSITION值指向列表中的一个有效位置。否则,MFC库(Microsoft Foundation Class Library)的调试版本将就此给出警告声明。

示例:
CObList list;
CObject* pa;
POSITION pos;

list.AddHead( new CAge( 21 ) );
list.AddHead( new CAge( 40 ) ); // List now contains (40, 21).
if( ( pos = list.GetTailPosition()) != NULL )
{
  pa = list.GetAt( pos ); // Save the old pointer for deletion.
  list.SetAt( pos, new CAge( 65 ) ); // Replace the tail element.
  delete pa; // Deletion avoids memory leak.
}
#ifdef _DEBUG
   afxDump.SetDepth( 1 );
   afxDump << "SetAt example: " << &list << "\n";
#endif

该程序的结果如下:
SetAt example: A CObList with 2 elements
a CAge at $4D98 40
a CAge at $4DB8 65

请参阅:
CObList::Find, CObList::GetAt, CObList::GetNext, CObList::GetPrev