Freigeben über


CObList::InsertBefore

Adds an element to this list before the element at the specified position.

POSITION InsertBefore(
   POSITION position,
   CObject* newElement 
);

Parameters

  • position
    A POSITION value returned by a previous GetNext, GetPrev, or Find member function call.

  • newElement
    The object pointer to be added to this list.

Return Value

A POSITION value that can be used for iteration or object pointer retrieval; NULL if the list is empty.

The following table shows other member functions that are similar to CObList::InsertBefore.

Class

Member Function

CPtrList

POSITION InsertBefore( POSITION position, void* newElement );

CStringList

POSITION InsertBefore( POSITION position, const CString& newElement );

POSITION InsertBefore( POSITION position, LPCTSTR newElement );

Example

See CObList::CObList for a listing of the CAge class.

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      

The results from this program are as follows:

InsertBefore example: A CObList with 3 elements

a CAge at $4AE2 40

a CAge at $4B02 65

a CAge at $49E6 21

Requirements

Header: afxcoll.h

See Also

Concepts

CObList Class

CObList Members

Hierarchy Chart

CObList::Find

CObList::InsertAfter