我正在尝试
map<string, int>
在我的程序中初始化一个静态映射,如下所示:
测试应用程序.h
class testApp(){
public:
void setup();
void update();
void renew();
static map<string, int> _someMap;
};
测试应用程序.cpp
testApp::setup(){
_someMap["something"] = 1;
_someMap["something2"] = 2;
cout<<_someMap["something"]<<"\n";
}
我不想使用boost
这种短暂的 map 并为我的代码添加源依赖项。我不在C++11
并且程序中没有构造函数,因为该类是某个框架的类。我在 Xcode 上并在执行上述操作时.cpp
,出现以下错误:
Undefined symbols for architecture i386:
"testApp::mapppp", referenced from:
testApp::setup() in testApp.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-->另外,假设我的地图是私有的,为此我在课堂上尝试过这样做:
...
private:
static someVariable;
static void someFunction();
.cpp
testApp::setup(){
someFunction();
}
错误:
Undefined symbols for architecture i386:
"testApp::_someMap", referenced from:
testApp::someFunction() in testApp.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)