// Definition of four different template classes. // Each defining static member template functions less_than and distance_to. // Notice that we just assume that getx and gety are public members in C! // Other designs may be possible - and preferable! #include struct FixedNorm{ template static bool less_than(const C& a, const C& b){ return false; } template static double distance_to(const C& a, const C& b){ return 7.0; } }; struct HorizontalNorm{ template static bool less_than(const C& a, const C& b){ return a.getx() < b.getx(); } template static double distance_to(const C& a, const C& b){ return fabs(a.getx() - b.getx()); } }; struct VerticalNorm{ template static bool less_than(const C& a, const C& b){ return a.gety() < b.gety(); } template static double distance_to(const C& a, const C& b){ return fabs(a.gety() - b.gety()); } }; templatedouble square(T a){ return a*a; } struct Norm{ template static bool less_than(const C& a, const C& b){ return (a.getx() < b.getx()) && (a.gety() < b.gety()); } template static double distance_to(const C& a, const C& b){ return sqrt(square(a.getx() - b.getx()) + square(a.gety() - b.gety())); } };