#include using namespace std; template class Comparator> struct Pair { Pair (const T1& p1_, const T1& p2_) :p1(p1_), p2(p2_) { } const T1& select() const { return Comparator::compare(p1, p2); } T1 p1, p2; }; template struct Smaller { static const T& compare (const T& t1, const T& t2) { return t1 < t2 ? t1 : t2; } }; template struct Greater { static const T& compare (const T& t1, const T& t2) { return t1 > t2 ? t1 : t2; } }; int main() { Pair p1(42,5); // p1 ist vom Typ T1, also int // Smaller wird mit p1, also int ausgeprägt // Pair wird mit int, Smaller ausgeprägt cout << p1.select() << endl; Pair p2(16.0, 22.0); cout << p2.select() << endl; }