mercredi 31 mai 2017

How to sort items in std::map by key's member variable? C++

here is an example. std::map<abc*, int>, at here abc is a class, so the key of the map is a pointer of class abc's object, the address of pointer changes for each running, therefore the order inside map is random. inside class abc, there is an ID member variable, for each object of class abc, ID is unique. My question: is it possible to let map sorts items by ID member variable instead by address of pointer. Thank you

Aucun commentaire:

Enregistrer un commentaire