So I have a basic Inventory system:
With this I am able to add items to the players inventory, but I don't know how to remove items. If I un-comment the orange line i get the following compiler error:Code:typedef struct sitem { string name; // A short name for the item string description; // A description of item } sitem; sitem sword = { "Sword", "A big heavy sword." }; sitem longsword = { "Longsword", "A huge Long Sword!" }; sitem poop = { "Poop", "A piece of poop" }; int main() { std::vector<sitem> inventory; inventory.push_back(longsword); // adds a longsword inventory.push_back(sword); // adds a sword inventory.push_back(poop); // adds a piece of poop for (std::vector<sitem>::const_iterator i = inventory.begin(); i != inventory.end(); ++i) { if (sword.name == "Sword") { // i = inventory.erase(); } } for (std::vector<sitem>::const_iterator i = inventory.begin(); i != inventory.end(); ++i) { std::cout << i->name << "\t" << std::endl << '\t' << i->description << endl; } return 0; }
" no matching function for call to `std::vector<sitem, std::allocator<sitem> >::erase()' "
I would just like to be able to remove any given item in the inventory, I might have to add an id for each current item in there as well.



LinkBack URL
About LinkBacks


