Chapter 7. Creating a Homegrown string class

You may recall the discussion near the beginning of Chapter 6 of native vs. user-defined variable types. I provided a list of native C++ variable types: char, short, long, float, double, bool, and int. We've already created several classes for our inventory control project, and now it's time to apply what we've learned to a more generally useful type, the string. We've been using strings for a long time and now it's time to see exactly how to implement our own string class. This class is similar, although not identical, to the standard string class we've been using.

First, though, you may be wondering why we should go through the trouble of learning how to implement a string class, when the standard library provides one for us. The answer is simple: creating a string class illustrates many of the subtle points of creating any class significantly more complicated than the StockItem class in the previous chapter. Since the purpose of this book is to teach you C++ programming, we might as well use instructional classes that at least resemble actual, useful classes like the string class.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset