CObList::InsertBefore

将元素添加到此在元素之前列出在指定的位置。

POSITION InsertBefore( 
   POSITION position, 
   CObject* newElement  
);

参数

  • 定位
    POSITION 值由以前的 GetNextGetPrev返回,或者 Find 成员函数调用。

  • newElement
    要添加的对象指针到此列表。

返回值

可以为迭代或对象指针检索使用的 POSITION 值; NULL,如果列表为空。

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

成员函数

CPtrList

POSITION InsertBefore( POSITION 位置, void* newElement);

CStringList

POSITION InsertBefore( POSITION 位置, const CString& newElement);

POSITION InsertBefore( POSITION 位置, LPCTSTR newElement);

示例

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

CObList list;
POSITION pos1, pos2;
list.AddHead(new CAge(21));
list.AddHead(new CAge(40)); // List now contains (40, 21). 
if ((pos1 = list.GetTailPosition()) != NULL)
{
    pos2 = list.InsertBefore(pos1, new CAge(65));
}
#ifdef _DEBUG
   afxDump.SetDepth(1);
   afxDump << _T("InsertBefore example: ") << &list << _T("\n");
#endif      

从此过程的结果如下:

InsertBefore example: A CObList with 3 elements

a CAge at $4AE2 40

a CAge at $4B02 65

a CAge at $49E6 21

要求

Header: afxcoll.h

请参见

参考

CObList Class

层次结构图

CObList::Find

CObList::InsertAfter