源程序:
#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;
}
运行结果:
原文:https://www.cnblogs.com/duanqibo/p/12266839.html