看板 C_Sharp 關於我們 聯絡資訊
※ [本文轉錄自 C_and_CPP 看板] 作者: StarTouching (撫星) 看板: C_and_CPP 標題: [語法] static的問題(VC) 時間: Fri Nov 30 17:40:36 2007 Visual C++ 2005 CLI(Window Form) 自行定義類別: class test { private: static int happy; public: static int get() { return happy; } }; 使用: int a = test::get(); 結果: compile時, syntax完全沒有問題 (宣告跟使用寫在兩個不同檔案, 個別compile都能過) 但是在Link階段出現錯誤(建置方案): Form1.obj : error LNK2020: 無法解析的語彙基元 (0A0000DF) "private: static int test::happy" (?happy@test@@0HA) Form1.obj : error LNK2001: 無法解析的外部符號 "private: static int test::happy" (?happy@test@@0HA) 如果把return happy;改成return 0; compile就會過, 但是我查書, static函式確實能使用private static variable才對 (事實上也只能用static變數) 有高手知道問題在哪嗎? 還是說Window form不給這樣寫? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.115.22.29 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 59.115.22.29 ※ 編輯: StarTouching 來自: 59.115.22.29 (11/30 18:15)