CObList::InsertBefore

POSITION InsertBefore( POSITION position, CObject* newElement );
throw ( CMemoryException );

Return Value

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

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.

Remarks

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

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 << "InsertBefore example: " << &list << "\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

CObList OverviewClass MembersHierarchy Chart

See Also   CObList::Find, CObList::InsertAfter