#include<iostream>
using namespace std;
class coord
{
int x,y;
public:
coord(int x1,int y1):x(x1),y(y1){}
int getx(){return x;}
int gety(){return y;}
int operator<(coord& c);
};
int coord::operator<(coord& c)
{
if(x<c.x)
if(y<c.y)
return 1;
return 0;
}
template<typename obj>
obj& min(obj& o1,obj& o2)
{
if(o1<o2)
return o1;
return o2;
}
int main()
{
coord c1(5,12);
coord c2(3,16);
coord c3=min(c1,c2);
cout<<"最小的坐标:"<<"("<<c3.getx()<<","<<c3.gety()<<")"<<endl;
double d1=2.99;
double d2=3.48;
cout<<"最小的数:"<<min(d1,d2)<<endl;
return 0;
}
有人能帮忙看下obj& min(obj& o1,obj& o2)这句的意思么,这个类外定义非模板函数是怎么回事 |