没看懂这个报错,也不知道代码该怎么写,求帮忙
#include<iostream>
using namespace std;
class clock {
private:
int hour,minute,second;
public:
clock(int m=0,int h=0,int s=0):hour(h),minute(m),second(s) {}
void show() {
cout<<hour<<":"<<minute<<":"<<second<<endl;
}
~clock();
clock operator++(int) {
second++;
if(second>=60) {
second-=60;
minute++;
}
if(minute>=60) {
minute-=60;
hour=(hour+1)%24;
}
return (*this);
}
};
int main() {
clock clock(11,59,58);
clock.show();
return 0;
}
~clock();改成
~clock() {}
析构函数没有函数体
析构函数要实现一下:~clock() {}
#include<iostream>
using namespace std;
class clocks {
private:
int hour, minute, second;
public:
clocks(int m = 0, int h = 0, int s = 0) :hour(h), minute(m), second(s) {}
void show() {
cout << hour << ":" << minute << ":" << second << endl;
}
~clocks(){}
clocks operator++(int) {
second++;
if (second >= 60) {
second -= 60;
minute++;
}
if (minute >= 60) {
minute -= 60;
hour = (hour + 1) % 24;
}
return (*this);
}
};
int main() {
clocks clok(11, 59, 58);
clok.show();
return 0;
}