Chapter 4. Lists

Whenever possible, we use lists in favor of arrays. This chapter explains ways of grouping things together in lists and how to iterate through them.

4.1

Introduction to Containers

96

4.2

Iterators

97

4.3

Relationships

99

Introduction to Containers

There are many occasions when it is necessary to deal with collections of things. The classic approach in languages like C is to use arrays to store such collections. In C++ arrays are regarded as evil. Here are a few good reasons to avoid using arrays.

  • Array subscripts are not checked to make sure that they are not out of range. A programmer using an array has the responsibility to write extra code to do the range checking.

  • Arrays are either fixed in size or they must use dynamic memory from the ...

Get An Introduction to Design Patterns in C++ with Qt 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.