自考新教材-p349_3(1)

源程序:

#include <iostream>
using namespace std;
template <class T>

class f
{
public:
T x, y;
void f1(T a, T b)
{
x = a;
y = b;
}
T max()
{
return (x > y) ? x : y;
}
};
//template <typename T>
int main()
{
f <double>a;
f <int>b;
a.f1(1.5, 3.8);
cout << a.x << "," << a.y << "," << a.max() << endl;
b.f1(-1,4);
cout << b.x << "," << b.y << "," << b.max() << endl;
system("pause");
return 1;
}

运行结果:

 

posted @ 2020-02-05 21:48  bobo哥  阅读(139)  评论(0编辑  收藏  举报