I have a function which creates an array of Maps:
map<string, int> *pMap
And a function which writes maps to the array:
int iAddMap(map<string, int> mapToAdd, map<string, int> *m, int i)
{
m = &(pMap[i]);
memcpy(m, mapToAdd, sizeof(map<string, int>));
}
And a function to get maps from the array
map<string, int>& getMap(int i)
{
return pMap[i];
}
I can write maps to the array without any issue, but every get call results in a seg fault:
int val;
// val defined after this
map<string, int> * pGetMap = &(getMap(val));
Any suggestions on why this is happening?