質問

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.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top