(If I got you) You might use a
std::unordered_map
too look-up items by their name property.
E.g.
#include <iostream>
#include <unordered_map>
using namespace std;
class Item
{
string name;
int value;
public:
Item(){}
Item(string name, int value):name{name},value{value}{}
string get_name(){ return name; };
int get_value() { return value; };
void show() const
{
cout << name << " " << value;
}
};
int main()
{
unordered_map<string, Item> inventory;
inventory.emplace("foo", Item{"foo", 100});
inventory.emplace("boo", Item{"boo", 20});
inventory.emplace("goo", Item{"goo", -50});
const auto & item_boo = inventory.at("boo"); item_boo.show(); cout << "\n";
const auto & item_bar = inventory.at("bar"); item_bar.show(); cout << "\n";
}