CObList::InsertBefore

將項目加入至這個清單在項目之前在指定的位置。

POSITION InsertBefore(
   POSITION position,
   CObject* newElement 
);

參數

  • position
    位置 值由先前 GetNextGetPrev尋找 成員函式呼叫會傳回。

  • newElement
    要加入的物件指標至這份清單。

傳回值

可以針對反覆項目或物件指標擷取使用的 位置 值; 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 類別

階層架構圖

CObList::Find

CObList::InsertAfter