O'Reilly logo

Navigating C++ and Object-Oriented Design by Gail Anderson, Paul Anderson

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

6.7. Putting It All Together

A Character List Class

Friend Classes” on page 246 introduces a List class that stores character strings. Here's another version of List with overloaded member functions.

Listing 6.4. List objects with remove()
// plist2.C - remove and print List of char * strings
#include <iostream.h>
#include "List2.h"

const int max = 3;

int main()
{
   static const char *brothers[] = { "groucho","chico","harpo" };
   List L1;

   for (int i = 0; i < max; i++)
      L1.append(brothers[i]);
   cout << "L1 has " << L1.length() << " strings" << endl;
   L1.print();

   L1.remove(L1.getEnd());          // remove last entry
   L1.remove("chico");              // find and remove "chico"
   L1.print();                      // display modified List
   return 0;
}

$ plist2 L1 has 3 strings groucho chico harpo groucho ...

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