#include <iostream>using namespace std;class Time{PRivate: int h,m,s;public: Time(); Time(int mh,int mm,int ms); //重载++运算符 Time Operator++(int); void ShowMe(); friend ostream& operator <<(ostream& output,Time &t);};ostream& operator<<(ostream& output,Time& t){ output<<t.h<<":"<<t.m<<":"<<t.s<<endl; return output;}Time Time::operator++(int){ //保存原值 Time tmp = *this; //将原值加 s = s+1; if(s == 60) { s = 0; m = m+1; if(m==60) { m = 0; h=h+1; if(h == 24) { h = 0; } } } //返回保存的那个原值 return tmp;}Time::Time(){ h=0; m=0; s=0;}Time::Time(int mh,int mm,int ms){ h=mh; m=mm; s=ms;}void Time::ShowMe(){ cout<<h<<":"<<m<<":"<<s<<endl;}int main(){ Time t(23,58,59); t++; //(t++).ShowMe(); cout<<t; return 0;}
新闻热点
疑难解答
图片精选