这段程序是学习函数模板的测试程序
#include
using namespace std;
class Interval
{
public:
Interval(int s,int e):start(s),end(e){}
int start;
int end;
};
bool operator>(const Interval &lhs,const Interval &rhs ){
if(lhs.start>rhs.start)
{
return true;
}else if(lhs.start==rhs.start){
return(lhs.end>rhs.end) ;
}else{
return false;
}
}
ostream operator<<(ostream& out,const Interval& i)
{
out<<"["<","<"]";
return out;
}
template <class T>
T mymax(const T &a,const T &b){
return (a>b?a:b);
}
int main()
{
int a=3,b=4;
cout<<"a,b之中的最大值是"<<mymax<int>(a,b)<Interval int1(1,2);
Interval int2 (1,3);
cout<<"int1与int2之间的最大值是"<<mymax(int1,int2)<return 0;
}
D:\collect2.exe [Error] ld returned 1 exit status
本来按一些博客的回答,改了系统环境变量,然后还是没有解决。
让它正常运行吧qwq
24行前面部分改ostream &operator?或者重启电脑?
ostream& operator<<(ostream& out,const Interval& i)