Re: [問題] 請教 C++ 的基本問題
class Time {//第六行,forward declaration of 'class Time'
public:
Time(); //第八行,invalid use of incomplete type 'class Time'
void setTime(int, int, int);
void printUniversal();
void printStandard();
private:
int hour;
int minute;
int second;
};
Time::Time(){
hour = minute = second = 0;
}
void Time::setTime(int h, int m, int s) {
hour = ((h>=0)&&(h<=23)?h:0);
minute = ((m>=0)&&(m<=59)?m:0);
second = ((s>=0)&&(s<=59)?s:0);
}
void Time::printUniversal() {
cout << hour << ":"
<< minute << ":"
<< second << endl;
};
void Time::printStandard() {
cout << ((hour == 0 || hour == 12) ? 12 : hour % 12)
<< ":" << minute
<< ":" << second
<< (hour < 12 ? "AM": "PM") << endl;
};
int main()
{ Time t;
t.printUniversal();
t.printStandard();
t.setTime(23,59,59);
t.printUniversal();
t.printStandard();
system("pause");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 123.195.32.199
→
01/06 22:34, , 1F
01/06 22:34, 1F
→
01/06 22:41, , 2F
01/06 22:41, 2F
→
01/06 23:32, , 3F
01/06 23:32, 3F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 3 篇):