作者StarTouching (抚星)
看板C_Sharp
标题[语法] static的问题(VC)
时间Fri Nov 30 17:40:49 2007
※ [本文转录自 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)