这是Microsoft Visual C++ 6.0的Debug,必须修改一下,采用旧标准,如下:
#include
#include
class Time
{
public:
int hour, minute, second;
void set(int h, int m, int s)
{
hour=h, minute=m, second=s;
}
friend Time& operator++(Time& a);
friend Time operator++(Time& a, int);
friend ostream& operator<<(ostream& o,const Time& t);
} ;
Time& operator++(Time& a )
{
if(!(a.second =(a.second +1)%60) && !(a.minute =(a.minute +1)%60))
a.hour =(a.hour +1)%24;
return a;
}
Time operator++(Time& a, int){
Time t(a);
if(!(a.second =(a.second +1)%60)&&!(a.minute =(a.minute +1)%60))
a.hour =(a.hour +1)%24;
return t;
}
ostream& operator<<(ostream& o,const Time& t){
o<return o< }
int main()
{
Time t;
t.set(11,59,58);
cout<cout<<++t;
return 0;
}
应该改成ostream& operator<<(ostream& o,const Time& t){
o<
}
setfill函数的参数是一个空字符。不是字符串。setfill(' ')单引号,且单引号内有一个空格
friend ostream& operator<<(ostream& o,const Time& t);
操作要写在方法内