Click on main.cpp to get source.
// File: C++Examples/Lists/main.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 "prof.h"
using namespace std;
// explicit instantiation of template class (for class PROFLIST)
template
class std::list<PROF>;
// printlist is implemented by C++ streamed I/O and overloaded <<
ostream& operator<<(ostream& os, const PROF& professor)
// concept demo'd: overloaded << operator for C++-style I/O
{os << professor.lname << " " << professor.fname;
return os;
} // end operator<<(ostream&, const PROF&)
ostream& operator<<(ostream& os, const PROFLIST& 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<<(ostream&, const PROFLIST&)
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 L;
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;
return 0;
}// end main