gpt4 book ai didi

c++ - "Undefined"C++类成员引用

转载 作者:太空宇宙 更新时间:2023-11-04 15:18:19 28 4
gpt4 key购买 nike

<分区>

链接这段代码时:

#include <map>
using std::map;
#include <string>
using std::string;
class C {
public:
static void dump() {
for (const auto& e : data) {
string(e.first);
}
}
private:
static map<string,map<string,string>> data;
};
int main() {
C::dump();
}

...我收到此错误:

/tmp/cc4W2iNa.o: In function `C::dump()':
test.cpp:(.text._ZN1C4dumpEv[_ZN1C4dumpEv]+0x9): undefined reference to `C::data'
collect2: error: ld returned 1 exit status

... 来自 g++ (GCC) 4.9.1。我做错了什么吗?

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