作者leicheong (睡魔)
看板C_Sharp
标题Re: [语法] static的问题(VC)
时间Fri Nov 30 18:42:25 2007
※ 引述《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