CS 340 - 3/7/13 Pointers to Functions - Templating uses this idea Template void sort (X arr[], int size); // uses operator< // uses the function passed by the parameter // for the comparison Template void sort (X arr[], int size, bool (*comp)(const X&, const X&)); // The C++ STL uses something like the following // that uses the default parameter value of // the overloaded operator< as the default // comparitor function/method Template void sort (X arr[], int size, bool (*comp)(const X&, const X&) = bool X::operator< (const X&) ); class Point { ... }; class Student { // possible data values: grade, name, UIN, Univeristy // major, ... ... }; bool compByName(const Student &s1, const Student &s2) { return (strcmp (s1.getName(), s2getName() ) < 0); } bool compByUIN(const Student &s1, const Student &s2) { return (s1.UIN().lessThan( s2.UIN() ) ); } Student array1[1000]; ... sort (array1, size, compByName ); sort (array1, size, compByUIN );