I have a class Inventory
class Inventory {
private:
vector<Item> items;
public:
void addItem(Item item) {
items.push_back(item);
}
void removeItem(string n) {
# Complete this
}
}
And a class Item
class Item {
private:
string name;
int power;
public:
Item(string n, int p) {
name = n; power = p;
}
string getName(){
return name;
}
};
how can I remove an item from items
if the name of the Item
is equal to a string n
?
something like:
bool matches(string name, Item item){
if (name == item.getName()) return true;
return false;
}
find_if(items.begin(), items.end() matches(someVariable, someObject));
TL;DR I need to remove an object from a vector if the value of a variable inside the object is equal to a variable passed to the function