associative arrays in C++ for any class type?
void CreatePlayer(int num)
{
Player * Player1 = new Player(num);
listOfPlayers[num] = Player1;
}
I need a class that can accomplish the above. I'm familiar with associative arrays in higher (managed) languages, but C++ is driving me nuts. Everything seems convoluted when trying to understand which class to use, or what you need to do to get that class to operate with the simplicity of the above code.
Please Help!
AlanPosted Oct 18, 2008, 6:49 PM
I'd check out the map class in the C++ standard template library. There are some examples of usage here:
http://www.yolinux.com/TUTORIALS/CppStlMultiMap.html
Your particular example, could be represented as follows:
map mapOfPlayers;
Player * Player1 = new Player(num);
mapOfPlayers[num] = Player1;