Click on main3A.cpp to get source.
// File: C++Examples/Lists/main3.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 <iostream>
#include <iterator>
#include <typeinfo>
#include "prof3A.h"
using namespace std;
ostream& operator<<(ostream& os, const PROF& professor)
{os << professor.lname << " " << professor.fname;
return os;
}// end operator<<(ostream&, const PROF&)
template<typename PROF_CONTAINER >
ostream& operator<< (ostream& os, const PROFLIST< PROF_CONTAINER >& L)
{ostream_iterator<PROF> 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<< <PROF_CONTAINER>
class PROFLIST< list<PROF> >; // instantiate template class
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
// instantiation not allowed here: class PROFLIST< list<PROF> >;
PROFLIST< deque<PROF> > L;
PROFLIST< set<PROF> > L2;
cout << "Using container " << typeid(L).name() << endl;
L.hire(caviness);
// hire and fire are mem funs of PROFLIST
// the have a reference arg, so no pointer to PROF passed in
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 << "Using container " << typeid(L2).name() << endl;
L2.hire(kaltofen);cout << L2 << endl;
L2.hire(saunders);cout << L2 << endl;
L2.fire("Kaltofen"); cout << L2 << endl;
return 0;
}// end main