#include <iostream>
using namespace std;
template <class numtype> class Compare //类模板
{public:
//Compare(numtype a,numtype b){x=a;y=b;}
Compare(numtype a,numtype b);
numtype max(){return (x>y)?x:y;}
numtype min(){return (x<y)?x:y;}
private:
numtype x,y;
};
template <class numtype> Compare<numtype>::Compare(numtype a,numtype b)
{
x=a;
y=b;
}
int main( )
{
Compare<int>cmp1(3,7); //定义对象cmp1,用于两个整数的比较
cout << cmp1.max() << " is the Maximum" << endl;
cout << cmp1.min() << " is the Minimum" << endl << endl;
Compare<float> cmp2(45.78,93.6); //定义对象cmp2,用于两个浮点数的比较
cout << cmp2.max() << " is the Maximum" <<endl;
cout << cmp2.min() << " is the Minimum" <<endl<<endl;
Compare<char> cmp3('a', 'A'); //定义对象cmp3,用于两个字符的比较
cout << cmp3.max() << " is the Maximum" <<endl;
cout << cmp3.min() << " is the Minimum" <<endl;
return 0;
}