14. Dynamic Memory and the String Class

If you have a C++ compiler created in the past 5 or 10 years, you almost certainly have support for the Standard Template Library (STL), and that includes support for the automatic new string class described in Chapter 7—in addition to old-fashioned C-strings (arrays of char).

But in this chapter, we’re going to write our own version of the string class, calling it String. Why go to this trouble? Because the String class, even though it’s already provided for you, provides a perfect demonstration of many things you need to consider when writing your own classes, including the use of the new, delete, and this keywords.

And if by some chance you don’t have a compiler that supports STL, you can always use ...

Get C++ Without Fear: A Beginner’s Guide That Makes You Feel Smart, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.