C++中++运算符的重载

     void showTime() const;
Clock& operator ++();
Clock operator ++(int);
private:
int hour,minute,second;
};
Clock::Clock(int hour,int minute,int second){
if(<=hour&&hour<&&<=minute&&minute<&&<=second&&second<)
{
this->hour=hour;
this->minute=minute;
this->second=second;
}
else
cout<<"Time error!"<<endl;
} void Clock::showTime() const
{
cout<<hour<<":"<<minute<<":"<<second<<endl;
} Clock& Clock::operator ++()
{
second++;
if(second>=)
{
second-=;
minute++;
if(minute>=)
{
minute-=;
hour=(hour+)%;
}
return *this;
}
} Clock Clock::operator ++(int)
{
Clock old=*this;
++(*this);
return old;
} int main()
{
Clock myClock(,,);
cout<<"First time output:";
myClock.showTime();
cout<<"Show myClock++: ";
(myClock++).showTime();
cout<<"Show ++myClock: ";
(++myClock);
myClock.showTime();
return ;
}
上一篇:node+express+mongodb初体验


下一篇:appium --log-timestamp > appium.log