Re: [問題] 請教 C++ 的基本問題

看板Programming作者時間14年前 (2010/01/06 22:26), 編輯推噓0(003)
留言3則, 3人參與, 最新討論串2/3 (看更多)
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
linux的話不用加system("pause");
01/06 22:34, 1F

01/06 22:41, , 2F
基本上在command line執行都不用加
01/06 22:41, 2F

01/06 23:32, , 3F
好眼熟...螞蟻書
01/06 23:32, 3F
文章代碼(AID): #1BH9sDjZ (Programming)
文章代碼(AID): #1BH9sDjZ (Programming)