I have a program in which I wrote a class as follows:
.h File
typedef map<string, int> stringMap;
class SampleClass{
public:
void setup();
void update();
void draw();
private:
static stringMap _someMap;
static stringMap someMapInitializer();
};
.cpp file
//Initializer for static var
stringMap SampleClass::_someMap = someMapInitializer();
stringMap SampleClass::someMapInitializer(){
_someMap["something"] = 1;
return _someMap;
}
But on doing the above, I start getting "Program received signal EXC_BAD_ACCESS" error on running the program (compiles fine though)
The above function is changed to the following:
stringMap SampleClass::someMapIntializer(){
map<string, int> m;
m["somehting"] = 1;
return m;
}
works fine. What is wrong with the first case? Can't I access static member variables in a static function?