Using std::map properly


I want a list of ofSoundPlayers that I can refer to by name, so I have

// above class definition  
typedef std::map<std::string, ofSoundPlayer> soundList;  
// class .h  
soundList	sounds;  

Then to load & play a sound I do

sounds["myname"].loadSound("pathtowav", false);  

It works, but this is probably really bad. How does the allocation work in this instance? What is the best practice?

Would this be the correct way to do it?

sounds.insert ( pair<std::string, ofSoundPlayer>("myname", ofSoundPlayer()) );  


it’s the same, maps add an element automatically if the key you are using to access doesn’t exist.