类模板的问题
#include<iostream.h>template <class numtype>
class Compare
{
public:
Compare(numtype a,numtype b) // 这里是干吗用的?
{
x=a;
y=b;
} // 到这里
numtype max()
{
return (x>y)? x:y;
}
numtype min()
{
return (x<y)? x:y;
}
private:
numtype x,y;
};
int main()
{
Compare <int> cmpl(3,7);
cout<<cmpl.max()<<"max"<<endl;
cout<<cmpl.min()<<"min"<<endl;
Compare <float> cmp2(45.78,93.6);
cout<<cmp2.max()<<"max"<<endl;
cout<<cmp2.min()<<"min"<<endl;
Compare <char> cmp3('a','B');
cout<<cmp3.max()<<"max"<<endl;
cout<<cmp3.min()<<"min"<<endl;
return 0;
}