※ 引述《StarTouching (撫星)》之銘言:
: 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不給這樣寫?
根據MSDN library "The Symbol is not public":
Functions declared with the static modifier, by definition,
have file scope. Static variables have the same limitation.
Trying to access any static variables from outside of the file
in which they are declared can result in a compile error or an
unresolved external, depending on the specific coding of the
source files.
因此static function內不能存取private的variable.
ms-help://MS.VSCC.2003/MS.MSDNQTR.2006JAN.1033/vccore/html/
_error_the_symbol_is_not_public.htm
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 202.181.197.50