CObList::GetNext

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

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

Parameters

  • rPosition
    A reference to a POSITION value returned by a previous GetNext, GetHeadPosition, or other member function call.

Return Value

See the return value description for GetHead.

Remarks

You can use GetNext in a forward iteration loop if you establish the initial position with a call to GetHeadPosition 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 last in the list, then the new value of rPosition is set to NULL.

It is possible to remove an element during an iteration. See the example for RemoveAt.

참고

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::GetNext.

Class

Member Function

CPtrList

void*& GetNext( POSITION& rPosition );

const void* GetNext( POSITION& rPosition ) const;

CStringList

CString& GetNext( POSITION& rPosition );

const CString& GetNext( POSITION& rPosition ) const;

Example

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 head-to-tail order.
#ifdef _DEBUG
   for (pos = list.GetHeadPosition(); pos != NULL;)
   {
      afxDump << list.GetNext(pos) << _T("\n");
   }
#endif      

The results from this program are as follows:

a CAge at $479C 40

a CAge at $46C0 21

Requirements

Header: afxcoll.h

See Also

Reference

CObList Class

Hierarchy Chart

CObList::Find

CObList::GetHeadPosition

CObList::GetTailPosition

CObList::GetPrev

CObList::GetHead

Other Resources

CObList Members