CList::GetNext

TYPE**&GetNext(POSITION&rPosition);**

TYPEGetNext(POSITION&rPosition)const;

Return Value

If the list is const, GetNext returns a copy of the element at the head of the list. This allows the function to be used only on the right side of an assignment statement and protects the list from modification.

If the list is not const, GetNext returns a reference to an element of the list. This allows the function to be used on either side of an assignment statement and thus allows the list entries to be modified.

Parameters

TYPE

Template parameter specifying the type of the elements in the list.

rPosition

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

Remarks

Gets the list element identified by rPosition, then sets rPosition to the POSITION value of the next entry in the list. 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.

Example

// Define myList.
CList<CString,CString&> myList;

// Add two elements to the list.
myList.AddHead(CString("ABC"));
myList.AddHead(CString("123"));

// Dump the list elements to the debug window.
POSITION pos = myList.GetHeadPosition();
for (int i=0;i < myList.GetCount();i++)
{
   TRACE("%s\r\n", (LPCSTR) myList.GetNext(pos));
}

CList OverviewClass MembersHierarchy Chart

See Also   CList::Find, CList::GetHeadPosition, CList::GetTailPosition, CList::GetPrev, CList::GetHead