Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top