Original Post
I'm trying to program an inventory in c++. I'm not really doing a game right now, I just want to write some reusable inventory code in case I need it later (and I was curious as to how this stuff is done). My vision of the inventory would be like one in one of those old-style rpgs, which is basically a (scrollable) list of items in text. When selected the user can use or dispose the item (for example). I thought of creating a class Item, which would hold every item's information like name, type etc. I was also going to store these in a STL list, and maybe attach that list to an object player (or something like that). My biggest question is how to make it so that when the user chooses to use a certain item that each item perform a different task? I guess the class Item could have a function called use() or something, but the code inside this function would have to change depending on the item such as healing health points vs. increasing the player's speed. I thought maybe creating some child classes that each did something different (ie a class for changing the player's stats the other for changing hit points etc.), but I was sure if there was a standard more "elegant" way of creating inventories. I've already searched for code examples but haven't found any. Any help or links to code (I'm sure someone already has had to solve the problem) would be greatly appreciated.