#include <iostream>using namespace std;class Time{PRivate:    int h,m,s;public:    Time();    Time(int mh,int mm,int ms);    //重載++運(yùn)算符    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;            }        }    }    //返回保存的那個(gè)原值    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;}
| 
 
 | 
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注