Compartilhar via


CList::GetHead

Gets the head element (or a reference to the head element) of this list.

const TYPE& GetHead( ) const; 
TYPE& GetHead( );

Parameters

  • TYPE
    Template parameter specifying the type of object in the list.

Return Value

If the list is const, GetHead 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, GetHead returns a reference to the element at the head 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.

Remarks

You must ensure that the list is not empty before calling GetHead. If the list is empty, then the Debug version of the Microsoft Foundation Class Library asserts. Use IsEmpty to verify that the list contains elements.

Example

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

// Add an element to the front of the list.
myList.AddHead(CString(_T("ABC")));

// Verify the element was added to the front of the list.
ASSERT(CString(_T("ABC")) == myList.GetHead());      

Requirements

Header: afxtempl.h

See Also

Reference

CList Class

Hierarchy Chart

CList::GetTail

CList::GetTailPosition

CList::AddHead

CList::RemoveHead