第九章课后练习题(P352_5_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;
}

posted @ 2020-04-21 08:25  CollisionDimension  阅读(109)  评论(0)    收藏  举报