64,637
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include "clock.h"
using namespace std;
int main()
{
Clock k(10,20,30);
k.showTime();
(++k).showTime();
cout<<"------------------------------"<<endl;
k.showTime();
(k++).showTime();
return 0;
}
#ifndef _CLASS_H
#define _CLASS_H
class Clock
{
public:
Clock(int h,int m,int s);
void showTime();
friend Clock operator++(Clock c);
friend Clock operator++(Clock c,int);
private:
int hour;
int min;
int sec;
};
#endif
#include <iostream>
#include "clock.h"
using namespace std;
Clock::Clock(int h,int m,int s)
{
hour=h;
min=m;
sec=s;
}
void Clock::showTime()
{
cout<<hour<<":"<<min<<":"<<sec<<endl;
}
Clock operator++(Clock c)
{
c.sec++;
cout<<"++x"<<endl;
return c;
}
Clock operator++(Clock c,int)
{
Clock d=c;
c.sec++;
cout<<"X++"<<endl;
return d;
}