问题遇到的现象和发生背景
这段程序是学习函数模板的测试程序
用代码块功能插入代码,请勿粘贴截图
#include <iostream>
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<<"["<<i.start<<","<<i.end<<"]";
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)<<endl;
Interval int1(1,2);
Interval int2 (1,3);
cout<<"int1与int2之间的最大值是"<<mymax<Interval>(int1,int2)<<endl;
return 0;
}
运行结果及报错内容
D:\collect2.exe [Error] ld returned 1 exit status
我的解答思路和尝试过的方法
本来按一些博客的回答,改了系统环境变量,然后还是没有解决。
我想要达到的结果
让它正常运行吧qwq