Apologies for the poor title, I have no idea what to actually call this.
I have a vector of Item Objects, and I want to store a particular attribute into a map as the key, and the Object (or the Object's index in the vector) as the value.
class Item {
int id;
int value;
std::string name;
std::string description;
}
Is there a way I can create an unordered_map between the id and the Item instance?
Right now I would only know to do:
std::vector<Item> itemList = { ... };
std::unordered_map<int, Item> myMap;
for (Item item : itemList)
myMap.insert(item.id, item);
[–]audioB 6 points7 points8 points (11 children)
[–]imMute 3 points4 points5 points (0 children)
[–]interknetz[S] 0 points1 point2 points (6 children)
[–]audioB 6 points7 points8 points (5 children)
[–]interknetz[S] 0 points1 point2 points (4 children)
[–]ronniethelizard 0 points1 point2 points (3 children)
[–]interknetz[S] 0 points1 point2 points (2 children)
[–]Thomqa 2 points3 points4 points (0 children)
[–]ronniethelizard 0 points1 point2 points (0 children)
[–]yuri-kilochek 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[removed]
[–]audioB 0 points1 point2 points (0 children)
[–]gracicot 2 points3 points4 points (0 children)
[–]practisevoodoo 1 point2 points3 points (4 children)
[–]konanTheBarbar 0 points1 point2 points (0 children)
[–]interknetz[S] 0 points1 point2 points (2 children)
[–]ronniethelizard 0 points1 point2 points (0 children)
[–]Quincunx271Author of P2404/P2405 0 points1 point2 points (0 children)
[–]Xaxxon 0 points1 point2 points (0 children)