CObList::SetAt

将该元素在特定位置。

void SetAt( 
   POSITION pos, 
   CObject* newElement  
);

参数

  • pos
    要设置的元素的 POSITION

  • newElement
    到列表要写入的 CObject 指针。

备注

类型 POSITION 的变量是列表的密钥。 这不是同样作为索引,因此,您不能对 POSITION 值。 SetAt 写入指定的位置 CObject 指针悬停在列表。

您必须确保 POSITION 值表示列表中的有效位置。 如果是无效的,则选件Microsoft基础类库的调试版本断言。

下表显示类似于 CObList::SetAt的其他成员函数。

成员函数

CPtrList

void SetAt( POSITION pos, const CString& newElement);

CStringList

void SetAt( POSITION pos, LPCTSTR newElement);

示例

用于列表 CAge 选件类参见 CObList::CObList

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 << _T("SetAt example: ") << &list << _T("\n");
#endif      

从此过程的结果如下:

SetAt example: A CObList with 2 elements

a CAge at $4D98 40

a CAge at $4DB8 65

要求

Header: afxcoll.h

请参见

参考

CObList Class

层次结构图

CObList::Find

CObList::GetAt

CObList::GetNext

CObList::GetPrev