Case Study: A Resizable Array

It can be a useful exercise to reinvent the wheel, especially if you don't insist on using the results. std::vector and std::valarray (see Appendix B, “A Short Library Reference”) will do well for most applications and have been carefully designed. Also, by now, C++ programmers know them and may be irritated if they have to learn new classes that you have created to do the same thing as std::vector and std::valarray.

But the issues of copying and value semantics are best illustrated by something nontrivial. Furthermore, the resizable array discussed in this section shows how you can have objects that obey value semantics that are not expensive to use.

As mentioned previously in this chapter, you should always pass ...

Get C++ By Example: UnderC Learning Edition 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.