Is there any practical way to get objects to work with maps? (I don’t really know much about maps so sorry if this is a bad question). I’m interested in using a map for an inventory system that will contain item objects. An item object has a name, description, and money value. The key would be the item’s name, and the linking variable would be the the quantity of items I have for that particular item.
And if a map doesn’t work, does anyone have a good alternative to this type of system? I need something keeping track of the quantity of each type of item I have.
The C++ standard library template
mapis just a storage container so it can definitely be used with objects. The map will take your object as its templated argument parameter.A map would work well for your inventory system. Use something like:
Here’s a reference on the stdlib map and its functions:
http://www.cplusplus.com/reference/stl/map/
Look at the function pages for examples of how to iterate through/index a map, etc.