Click on main2.cpp to get source.
// File: C++Examples/Lists/main2.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 "prof2.h"
using namespace std;
ostream& operator<<(ostream& os, const PROF& professor)
{os << professor.lname << " " << professor.fname;
return os;
}// end operator<<(ostream&, const PROF&)
template< class 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>
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
PROFLIST< list<PROF> > L;
PROFLIST< set<PROF> > L2;
PROFLIST< vector<int> > L3;
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<PROF>" << 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<PROF>" << endl;
L2.hire(kaltofen);cout << L2 << endl;
L2.hire(saunders);cout << L2 << endl;
L2.fire("Kaltofen"); cout << L2 << endl;
// L3.hire(5); cout << L3 << endl;
return 0;
}// end main