书上的列题
#include<iostream.h>class clock
{
public:
clock(int newH=0,int newM=0,int newS=0);
void showtime();
void operator ++();
void operator ++(int);
private:
int hour,minute,second;
};
clock::clock(int newH,int newM,int newS)
{
if(0<=newH && newH<24 && 0<=newM && newM<60 && 0<=newS && newS<60)
{ hour=newH;
minute=newM;
second=newS;
}
else cout<<"modi shi lao da";
}
void clock::showtime()
{
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
void clock::operator ++()
{
second++;
if(second>=60)
{
second=second-60;
minute++;
if(minute>=60)
{
minute=minute-60;
hour++;
hour=hour%24;
}
}cout<<"clock++:";
}
void clock::operator ++(int)
{
second++;
if(second>=60)
{
second=second-60;
minute++;
if(minute>=60)
{
minute=minute-60;
hour++;
hour=hour%24;
}
}cout<<"++clock:";
}
void main()
{
clock myclock(23,59,59);
cout<<"first time output:";
myclock.showtime();
myclock++;
myclock.showtime();
++myclock;
myclock.showtime();
}
两个“++”运算符重载函数的函数体是一样的
怎么得到的不一样的结果,麻烦高手解释一下;0:0:0和0:0:1