#include
using namespace std;
class clock
{
public:
clock();
clock(int newH,int newM,int newS);//没见过可以带缺省值的,還有構造函數不可以用void
void showtime();
clock operator++();//前置++运算符//>
clock operator++(int x);//后置++运算符,要带(int)参数,无意义
private:
int Hour,Minute,Second;
};
/////////////////////////////////////////
clock::clock(){Hour=Minute=Second=0;}
clock::clock(int newH,int newM,int newS)
{
////////hour
Hour=newH%24;
////////minute
Minute=newM%60;
////////second
Second=newS%60;
}
clock clock::operator++()//++a的时候调用这个
{
++Second;
if(Second>59)
{
Second=1;++Minute;
if(Minute>59)
{Minute=1;
++Hour;}}
cout<<"++a"<
Hour=Hour%24;
return *this;
}
void clock::showtime()
{
cout<<"Hour : "< <<"Minute: "<<<"Second : "<}
void main()
{
clock myclock(23,45,100);
myclock.showtime();
++myclock;
myclock.showtime();
}
--------------------next---------------------
阅读(1163) | 评论(0) | 转发(0) |