关于<<重载问题,望指教
在ry.h中有如下声明:#ifndef TIME_H
#define TIME_H
class Time{
private:
int hours;
int minuets;
public:
Time();
Time(int h,int m=0);
void addMin(int m);
void addHr(int h);
void reset(int h=0,int m=0);
Time operator+(const Time& t)const;
Time operator-(const Time& t)const;
Time operator*(double n)const;
friend ostream& operator<<(ostream &os,const Time &t);
// void show()const;
};
#endif
其定义在ry.cpp中,如下:
#include"ry.h"
//#include<iostream>
Time::Time(){
hours=0;
minuets=0;
}
Time::Time(int h,int m){
hours=h;
minuets=m;
}
void Time::addMin(int m){
minuets+=m;
hours+=minuets/60;
minuets%=60;
}
void Time::addHr(int h){
hours+=h;
}
void Time::reset(int h,int m){
hours=h;
minuets=m;
}
Time Time::operator+(const Time &t)const{
Time sum;
sum.minuets=minuets+t.minuets;
sum.hours=hours+t.hours+sum.minuets/60;
sum.minuets%=60;
return sum;
}
Time Time::operator-(const Time &t)const{
Time diff;
int total1=minuets+60*hours;
int total2=t.minuets+60*t.hours;
diff.minuets=(total1-total2)%60;
diff.hours=(total1-total2)/60;
return diff;
}
Time Time::operator*(double n)const{
Time t;
t.minuets=(int)(minuets*n);
t.hours=(int)(hours*n)+t.minuets/60;
t.minuets%=60;
return t;
}
ostream & operator<<(ostream &os,const Time &t){
os<<"hours:"<<hours<<"\n"<<"minuets:"<<minuets<<endl;
return os;
}
/*
void Time::show()const{
std::cout<<"hours:"<<hours<<std::endl;
std::cout<<"minuets:"<<minuets<<std::endl;
}*/
请大家给我看看为什么不能识别ostream流