自考新教材-p352_1
源程序:
#include <iostream>
using namespace std;
template <class T>
class max
{
private:
T x, y;
public:
max(T a, T b)
{
x = a;
y = b;
}
T compare()
{
return (x > y) ? x : y;
}
};
//template <class T>
int main()
{
//T xx, yy;
//cout << "请输入两个数:";
//cin >> xx >> yy;
max <int>m1(2, 4);
cout << m1.compare() << endl;
max <double>m2(3.5, 1.7);
cout << m2.compare() << endl;
max <char>m3('m', 'p');
cout << m3.compare() << endl;
system("pause");
return 1;
}
运行结果: