Question

I am trying to insert data into a 2d map but the following code gives me a Access violation error.

void StateManager::AddState(string stateName, map<string, IBaseComponent*> stateComponents)
{
    // Add the state to the states map
    m_States.insert(pair<string, map<string, IBaseComponent*>>(stateName,stateComponents));
}

Can someone point out what I am doing wrong and how I can fix it ?

Edit: I tried inserting some test values into the map and that works fine. Must be a problem with the data I am inserting.

Was it helpful?

Solution

Turns out I was using the function before initializing the object that contains it. So m_States wasn't actually created yet. Hence the access violation error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top