CObList::InsertBefore
POSITION InsertBefore( POSITION position, CObject* newElement );
throw( CMemoryException );
返回值:
可用于迭代或对象指针检索的 POSITION 值。若列表为空,则返回NULL 。
参数:
position
由前面调用的GetNext, GetPrev或Find等成员函数返回的POSITION值。
newElement
指向要添加到该列表的对象指针。
说明:
在指定位置的元素前添加一个元素到列表中。
示例:
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 << "InsertBefore example: " << &list << "\n";
#endif
该程序的结果如下:
InsertBefore example: A CObList with 3 elements
a CAge at $4AE2 40
a CAge at $4B02 65
a CAge at $49E6 21
请参阅:
CObList::Find
,
CObList::InsertAfter