本帖最后由 头发 于 2020-12-20 20:24 编辑
#include<iostream>
using namespace std;
class Time{
int hour;
int minute;
int second;
public:
Time(int h=0,int m=0,int s=0):hour(h),minute(m),second(s){cout<<"构造函数!"<<endl;}
Time& add();
void show(){cout<<hour<<":"<<minute<<":"<<second<<endl;}
~Time(){cout<<"析构函数!"<<endl;}
};
Time& Time::add(){
second++;
if(second>=60){
second-=60;
minute++;
if(minute>=60){
minute-=60;
hour=(hour+1)%24;
}
}
return (*this);
}
int main(){
Time time(11,59,58);
for(int i=0;i<4;i++)
{
time.add();
time.show();
}
return 0;
}
呈上
那句要怎么读出来??没搞明白写那么复杂为啥 |