Hi,
Today/Yesterday I been having a few problem in my code which I manged to "solve", but I was wondering why my original approach didnt work?
Basically I have this std::map with a vector inside it like
std::map<int, std::vector<GameObject*>> testMap;
than i started to insert stuffs like so
mapTest.insert(std::pair<int, std::vector<GameObject*>>(renderID,{gameObjectTest})); //first try
mapTest.insert(mapTest.end(),std::pair<int, std::vector<GameObject*>>(renderID,{gameObjectTest})); //second try
I also tried to have a tempVector where I push_back the gameObjectTest in it and just had tempVector instead of { gameObjectTest }
At this point I got no syntax error or the likes, and when I ran the code it works great.
But when I tried to access the gameobject via
mapTest.at(0).at(0);
I get a std::out_of_range error,
but instead of using .at I tried to use
std::map<int, std::vector<GameObject*>>::iterator it = mapTest.begin();
it->second.at(0);
for now it works and I get no std::out_of_range error. I was wondering how come .at doesnt work but .begin (aka iterator) works?