I am trying to initialise a static map of
map<string, int>
in my program as follows:
testApp.h
class testApp(){
public:
void setup();
void update();
void renew();
static map<string, int> _someMap;
};
testApp.cpp
testApp::setup(){
_someMap["something"] = 1;
_someMap["something2"] = 2;
cout<<_someMap["something"]<<"\n";
}
I don't want to use boost
for this short use of map and add source dependency for my code. I am not on C++11
and I don't have the constructor here in the program since the class is some framework's class. I am on Xcode and on doing the above in .cpp
, I get the following error:
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)
-- >Additionally, let's say my map is private, for which I tried doing this in my class:
...
private:
static someVariable;
static void someFunction();
.cpp
testApp::setup(){
someFunction();
}
Error:
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)