I have a vector of tuple and I push back an item in it, then if i push back the same item, i want it search the vector of tuple and if it finds the same item, then dont add it to the inventory or remove duplicate, but I cant seem to figure out how. I tried to use an iterator but it keeps giving me an error.
Well in my other project I have a tuple as the players inventory in the player class, the tuple holds an Item object and an int which represents how much for that item the player has, i could have used pair but i decided on tuple and I can easily expand it when needed, like say if I need it to hold an ID for the item as well. This code above I wrote in a blank project to just try to understand how tuple works and how to iterate through it.
What would be a better way to do an inventory? is just a vector that holds Item objects fine? I've been thinking about this for a few hours. and in my program I have an item class and the constructor looks like this:
with a regular vector and add a variable to Item that tracks how many the player has in their inventory, but I dont really know. I almost feel like that variable belongs in the player class, but im unsure.
I have it as a tuple so i can track the item and the amount owned and increment/decrement the amount owned easily, but I guess I could do that another way as well, just not too sure how yet.
This is a very basic example I just whipped this up to illustrate what I'm talking about, it's my first attempt at using composition as well, I think I may have wound up just using individual classes as their own thing though.