Click here to change the theme.

The newer MFC collection classes use templates, so they can be type-safe yet work for most types. The collection classes that use templates are: CArray, CMap, CList, CTypedPtrArray, CTypedPtrList and CTypedPtrMap. A list of objects, such as a list or array of integers, can easily be created using template classes such as CList and CArray. The following pages show sample uses of various collections.

The following are samples of using the older style collection classes. The MFC documentation suggests to avoid use of these, though. I agree that they should be avoided but it is probably not as much of a problem if you use one of the type-specific ones; they are: CByteArray, CDWordArray, CStringList, CStringArray, CMapStringToString, CWordArray. The simplest collections to use are CStringList and CStringArray.

Finally, I have a sample of Sorting a CArray.

Also see Sorting a MFC Array Collection Using STL.