I'm practicing some C++ and was wondering what the best approach is to creating a basic Inventory System, where item's have their own ID assigned to them. I'm trying to expand on my C++ skills, so I am making small little programs for practice.
I've created a class that holds the ItemName & ItemID. A Getter and Setter have been added to get the items ID, but I seem to be struggling on what to do next and how I assign an item with an ID number. For example, saying Silver Key has an item ID of 3.
Also, when storing this in an inventory what type of Array would be best to use? I have done some previous research on Vector Arrays and Dynamic Arrays, but forgotten how to implement them. I can research what is the best one to use and try and implement it myself once I know which one is best to use.
One thing that would help is to post the code you have written instead of letting everyone guess at what you have done. Someone might see something you have done wrong or that could be improved on.
Arrays based on the class for the type will work. I tend to use "std::vector"s over arrays. With a vector it will hold only what you need and getting the amount of elements in the vector is just asking the right question "vectorName.size()". Note the return value is an "unsigned int".
In terms to assigning the items with the method used, is there a way to set up item IDs in a separate file, and then call that in the main file and add it to the inventory.
For example, if a player wishes to pick up a key, with an item id of 1, can that be added to the inventory by calling another function or something that holds the details for the key?
I've been messing around with this code for a few days and understand what's going on (to a degree).
I've mesmerized the code and typed it out pretty much how it appears above, but when I go to run the program, all I get is
1 2
C4018 '<': signed/unsigned mismatch (Line 55)
C3867 'inventory::getName': non-standard syntax; use '&' to create a pointer to member (Line 56)