Trouble in String City

This definition of a String class is incomplete. Of course, for brevity's sake, it fails to implement many useful methods, such as overloading the <, ==, and > operators to facilitate string comparisons. But the class flaws are more fundamental than that. As proof, consider this simple program (Listing 11.4), using the current String implementation:

Listing 11.4 problem1.cpp.
 // problem1.cpp -- uses a function with a String argument // compile with strng1.cpp #include <iostream> using namespace std; #include "strng1.h" void showit(String s, int n); int main() { String motto("Home Sweet Home"); showit(motto, 3); return 0; } void showit(String s, int n) // show String s n times { for (int i = 0; i < n; i++) cout << s << ...

Get The Waite Group's C++ Primer Plus, Third 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.