小弟刚学了一个学期的C++,下面这份代码请大佬们帮忙看看哪里出错了
头文件#ifndef thehead
#define thehead
using namespace std;
class Time {
friend ostream &operator<<(ostream &os,const Time &time);
int second;
public:
Time (int tt,int mm,int ss)
{second=tt*3600+mm*60+ss;}
bool operator>(const Time &time2)
{return second>time2.second;}
bool operator<(const Time &time2)
{return second<time2.second;}
bool operator==(const Time &time2)
{return second==time2.second;}
bool operator>=(const Time &time2)
{return second>=time2.second;}
bool operator<=(const Time &time2)
{return second<=time2.second;}
bool operator!=(const Time &time2)
{return second!=time2.second;}
Time &operator+=(const Time &othertime)
{second+=othertime.second;return *this;}
Time &operator-=(const Time &othertime)
{second-=othertime.second;return *this;}
int operator-(const Time &time2)
{return second-time2.second; }
Time &operator++()
{
second++;
return *this;
}
Time &operator--()
{
second--;
return *this;
}
Time operator++(int x)
{
Time tmp=*this;
second++;
return tmp;
}
Time operator--(int x)
{
Time tmp=*this;
second--;
return tmp;
}
};
#endif // thehead
operator<<函数的实现文件 1.cpp
#include<iostream>
#include"thehead.h"
using namespace std;
ostream &operator<<(ostream &os,const Time &time)
{
int tt,mm,ss;
tt=(time.second)/3600;
mm=((time.second)%3600)/60;
ss=(((time.second)%3600)%60);
os<<tt<<":"<<mm<<":"<<ss;
return os;
}
main函数文件 2.cpp
#include<iostream>
#include"thehead.h"
using namespace std;
int main ()
{
int a,b,c,d,e;
Time time1(16,40,39);
Time time2(15,26,20);
Time othertime(2,25,10);
if(time1>time2)
cout<<time1-time2;
cout<<time1;
cout<<time1+=othertime;
return 0;
}
小弟在执行1.cpp时出现的编译错误为:undefined reference to `WinMain@16'和error: ld returned 1 exit status
执行2.cpp时出现的编译错误为:error: no match for 'operator+=' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'Time')
把2.cpp的cout<<time1+=othertime;注释掉的话出现的编译错误就为:undefined reference to `WinMain@16'和error: ld returned 1 exit status
拜托各位大佬帮忙解答一下,感激不尽!