// File: C++Examples/Lists/main2A.C // This is the C++ implementation of ../CExamples/Lists // Note: the original C program was rewritten to reflect // modern C++ principle (it would work as written) // those "modern" C++ principles are explained as // demo'd concepts in the comments #include #include #include "prof2A.h" using namespace std; ostream& operator<<(ostream& os, const PROF& professor) {os << professor.lname << " " << professor.fname; return os; }// end operator<<(ostream&, const PROF&) template< template class CONTAINER > ostream& operator<< (ostream& os, const PROFLIST< CONTAINER >& L) {ostream_iterator out(os, "\n"); copy(L.begin(), L.end(), out); // concepts demo'd: STL copy algo used with ostream_iterator for output return os; }// end operator<< int main(int argc, char* argv[]) // there are no args to main, but for later use always define these {PROF caviness("Caviness", "Bob", 'F', 100.0, 1, 4.5) ,kaltofen("Kaltofen", "Erich", 'L', 50.0, 1, 3.0) ,saunders("Saunders", "Benjamin",'D', 95.0, 2, 3.5) ; // initialization is by constructor args // concepted demo'd: template-template parameters PROFLIST< list > L; PROFLIST< set > L2; L.hire(caviness); // hire and fire are mem funs of PROFLIST // the have a reference arg, so no pointer to PROF passed in cout << "list" << endl; cout << L << endl; // cout << is the standard way to "serialize" objects to a stream L.hire(saunders); cout << L << endl; L.hire(kaltofen); cout << L << endl; L.fire("Kaltofen"); cout << L << endl; L.fire("Caviness"); cout << L << endl; L.fire("Pipes"); cout << L << endl; cout << "--------" << endl; cout << "set" << endl; L2.hire(kaltofen);cout << L2 << endl; L2.hire(saunders);cout << L2 << endl; L2.fire("Kaltofen"); cout << L2 << endl; return 0; }// end main