O'Reilly logo

An Introduction to Design Patterns in C++ with Qt™, Second Edition by Paul Ezust, Alan Ezust

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4: Lists

Whenever possible, you should use lists instead of arrays. This chapter introduces containers and discusses various ways of grouping things in lists and how to iterate through them.

4.1 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 (Section 21.4) to store such collections. In C++, arrays are regarded as evil.

Following are a few good reasons to avoid using arrays in C++:

• Neither the compiler nor the runtime system checks array subscripts to make sure that they are within the correct range.

• A programmer using an array has the responsibility to write extra code to do the range checking.

• Arrays are either ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required