[問題] 建構子問題

看板C_and_CPP作者 (qq)時間11年前 (2014/06/21 20:15), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
class Time { public: Time(){count=999;} static int howmany(){count++;return count;} private: static int count; }; int _tmain(int argc, _TCHAR* argv[]) { Time x; cout<<x.howmany()<<endl; //cout<<Time::howmany()<<endl; system("pause"); return 0; } 請問一下各位 這裡我將count設成靜態為什麼會出現錯誤? 還有這行 cout<<Time::howmany()<<endl; ::這裡是什麼意思? 這行編譯有過不了 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.233.165.225 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1403352915.A.DD9.html

06/21 22:30, , 1F
Static Member要先initialize哦
06/21 22:30, 1F

06/22 09:36, , 2F
要init
06/22 09:36, 2F
文章代碼(AID): #1JfNTJtP (C_and_CPP)