C++重载操作符的问题

来源:百度知道 编辑:UC知道 时间:2024/05/21 12:58:10
最近刚刚看C++,按照书本上的例题打了段程序,在VC6下编译却通不过,在下菜鸟,请高人指教,多谢!
下面是程序代码,讲的是重载增量操作符,程序设计的是一个具有时、分、秒的Time类。
#include<iostream>
#include<iomanip>
using namespace std;

class Time{
int hour,minute,second;
public:
void set(int n, int m, int s){ hour=n, 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<<setfill('0')<<setw(2)<<t.hour<<&qu

#include "stdafx.h"

#include<iostream.h>
#include<iomanip.h>

class Time{

public: int hour,minute,second;
void set(int n, int m, int s){ hour=n, 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<<setfill('0')<<setw(2)<<t.hour<<":"<<setw(2)<<t.minute<<":";
r