Collections Topics

HomeOverviewHow Do ISampleTutorial

This group of articles explains the MFC collection classes.

The Microsoft Foundation Class Library provides collection classes to manage groups of objects. These classes are of two types:

Other topics covered in this article include:

Tip   The nontemplate collection classes have been provided by MFC beginning with MFC version 1.0. If your code already uses these classes, you can continue to use them. If you write new type-safe collection classes for your own data types, consider using the newer template-based classes.

Collection Shapes

A collection class is characterized by its “shape” and by the types of its elements. The shape refers to the way the objects are organized and stored by the collection. MFC provides three basic collection shapes: lists, arrays, and maps (also known as dictionaries). You can pick the collection shape most suited to your particular programming problem.

Each of the three provided collection shapes is described briefly below. the table Collections: Choosing a Collection Class compares the features of the shapes to help you decide which is best for your program.

The Template-Based Collection Classes

The easiest way to implement a type-safe collection that contains objects of any type is to use one of the MFC template-based classes. For examples of these classes, see the MFC Advanced Concepts sample COLLECT.

The following table lists the MFC template-based collection classes.

Collection Template Classes

Collection contents Arrays Lists Maps
Collections of objects of any type CArray CList CMap
Collections of pointers to objects of any type CTypedPtrArray CTypedPtrList CTypedPtrMap

The Collection Classes Not Based on Templates

If your application already uses MFC nontemplate classes, you can continue to use them, although for new collections you should consider using the template-based classes. The following table lists the MFC collection classes not based on templates.

Nontemplate Collection Classes

Arrays Lists Maps
CObArray CObList CMapPtrToWord
CByteArray CPtrList CMapPtrToPtr
CDWordArray CStringList CMapStringToOb
CPtrArray CMapStringToPtr
CStringArray CMapStringToString
CWordArray CMapWordToOb
CUIntArray CMapWordToPtr

The previous table in the article Collections: Choosing a Collection Class describes the MFC collection classes in terms of their characteristics (other than shape):

Further Reading About Collections

The following articles describe how to use the collection classes to make type-safe collections and how to perform a number of other operations using collections: