//DISPLAY 17.8 Implementation of GenericList //This is the implementation file: genericlist.cpp //This is the implementation of the class template named GenericList. //The interface for the class template GenericList is in the //header file genericlist.h. #ifndef GENERICLIST_CPP #define GENERICLIST_CPP #include #include #include "genericlist.h" //This is not needed when used as we are using this file, //but the #ifndef in genericlist.h makes it safe. using namespace std; namespace listsavitch { //Uses cstdlib: template GenericList::GenericList(int max) : maxLength(max), currentLength(0) { item = new ItemType[max]; } template GenericList::~GenericList( ) { delete [] item; } template int GenericList::length( ) const { return (currentLength); } //Uses iostream and cstdlib: template void GenericList::add(ItemType newItem) { if ( full( ) ) { cout << "Error: adding to a full list.\n"; exit(1); } else { item[currentLength] = newItem; currentLength = currentLength + 1; } } template bool GenericList::full( ) const { return (currentLength == maxLength); } template void GenericList::erase( ) { currentLength = 0; } template ostream& operator <<(ostream& outs, const GenericList& theList) { for (int i = 0; i < theList.currentLength; i++) outs << theList.item[i] << endl; return outs; } }//listsavitch #endif // GENERICLIST_CPP Notice that we have enclosed all the template // definitions in #ifndef... #endif.