// An excerpt of the previously shown program that uses the compare template function. // Here we show the use of compare on instances of class Point. #include #include #include "point.h" class ComparsionProblem{}; template int compare(const T &v1, const T &v2){ if (v1 < v2) return -1; else if (!(v1 < v2) && !(v2 < v1)) return 0; else if (v2 < v1) return 1; else throw ComparsionProblem(); } int main(){ using namespace std; Point p1(1,2), p2(3,4); cout << compare(p1, p1) << endl; // 0 cout << compare(p1, p2) << endl; // -1 cout << compare(p2, p1) << endl; // 1 }