This topic has not yet been rated - Rate this topic

CObList::GetPrev

Gets the list element identified by rPosition, then sets rPosition to the POSITION value of the previous entry in the list.

CObject*& GetPrev(
   POSITION& rPosition 
);
const CObject* GetPrev(
   POSITION& rPosition 
) const;
rPosition

A reference to a POSITION value returned by a previous GetPrev or other member function call.

See the return value description for GetHead.

You can use GetPrev in a reverse iteration loop if you establish the initial position with a call to GetTailPosition or Find.

You must ensure that your POSITION value represents a valid position in the list. If it is invalid, then the Debug version of the Microsoft Foundation Class Library asserts.

If the retrieved element is the first in the list, then the new value of rPosition is set to NULL.

Note Note

As of MFC 8.0 the const version of this method has changed to return const CObject* instead of const CObject*&. This change was made to bring the compiler into conformance with the C++ standard.

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

Class

Member Function

CPtrList

void*& GetPrev( POSITION& rPosition );

const void* GetPrev( POSITION& rPosition ) const;

CStringList

CString& GetPrev( POSITION& rPosition );

const CString& GetPrev( POSITION& rPosition ) const;

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


CObList list;
POSITION pos;

list.AddHead(new CAge(21));
list.AddHead(new CAge(40)); // List now contains (40, 21).
// Iterate through the list in tail-to-head order.
for (pos = list.GetTailPosition(); pos != NULL;)
{
#ifdef _DEBUG
    afxDump << list.GetPrev(pos) << _T("\n");
#endif
}      


The results from this program are as follows:

a CAge at $421C 21

a CAge at $421C 40

Header: afxcoll.h

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ