gpt4 book ai didi

c++ - 为什么尝试在类中设置静态变量时出现链接器错误?

转载 作者:行者123 更新时间:2023-11-30 01:23:53 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
static member variable in a class
What is an undefined reference/unresolved external symbol error and how do I fix it?

class test_struct {
static int number;
public:
static void set() {
number = 42;
}
};

int main() {
test_struct::set();
}

错误是:

[...]Temp\ccGGxEAz.o:test.cpp:(.text.startup+0xf): undefined reference to `test_struct::number'
collect2.exe: error: ld returned 1 exit status

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com