共用方式為


CList Class

Supports ordered lists of nonunique objects accessible sequentially or by value.

template< class TYPE, class ARG_TYPE = const TYPE& > 
class CList : public CObject

Members

Public Constructors

Name

Description

CList::CList

Constructs an empty ordered list.

Public Methods

Name

Description

CList::AddHead

Adds an element (or all the elements in another list) to the head of the list (makes a new head).

CList::AddTail

Adds an element (or all the elements in another list) to the tail of the list (makes a new tail).

CList::Find

Gets the position of an element specified by pointer value.

CList::FindIndex

Gets the position of an element specified by a zero-based index.

CList::GetAt

Gets the element at a given position.

CList::GetCount

Returns the number of elements in this list.

CList::GetHead

Returns the head element of the list (cannot be empty).

CList::GetHeadPosition

Returns the position of the head element of the list.

CList::GetNext

Gets the next element for iterating.

CList::GetPrev

Gets the previous element for iterating.

CList::GetSize

Returns the number of elements in this list.

CList::GetTail

Returns the tail element of the list (cannot be empty).

CList::GetTailPosition

Returns the position of the tail element of the list.

CList::InsertAfter

Inserts a new element after a given position.

CList::InsertBefore

Inserts a new element before a given position.

CList::IsEmpty

Tests for the empty list condition (no elements).

CList::RemoveAll

Removes all the elements from this list.

CList::RemoveAt

Removes an element from this list, specified by position.

CList::RemoveHead

Removes the element from the head of the list.

CList::RemoveTail

Removes the element from the tail of the list.

CList::SetAt

Sets the element at a given position.

Parameters

  • TYPE
    Type of object stored in the list.

  • ARG _ TYPE
    Type used to reference objects stored in the list. Can be a reference.

Remarks

CList lists behave like doubly-linked lists.

A variable of type POSITION is a key for the list. You can use a POSITION variable as an iterator to traverse a list sequentially and as a bookmark to hold a place. A position is not the same as an index, however.

Element insertion is very fast at the list head, at the tail, and at a known POSITION. A sequential search is necessary to look up an element by value or index. This search can be slow if the list is long.

If you need a dump of individual elements in the list, you must set the depth of the dump context to 1 or greater.

Certain member functions of this class call global helper functions that must be customized for most uses of the CList class. See Collection Class Helpers in the "Macros and Globals" section.

For more information on using CList, see the article Collections.

Example

// CList is a template class that takes two template arguments. 
// The first argument is type stored internally by the list, the 
// second argument is the type used in the arguments for the 
// CList methods. 

// This code defines a list of ints.
CList<int,int> myIntList;

// This code defines a list of CStrings
CList<CString,CString&> myStringList;

// This code defines a list of MYTYPEs, 
// NOTE: MYTYPE could be any struct, class or type definition
CList<MYTYPE,MYTYPE&> myTypeList;

Inheritance Hierarchy

CObject

CList

Requirements

Header: afxtempl.h

See Also

Reference

CObject Class

Hierarchy Chart

CMap Class

CArray Class

Concepts

MFC Sample COLLECT