How can I use std::maps with user-defined types as key?
You don’t have to define operator< for your class, actually. You can also make a comparator function object class for it, and use that to specialize std::map. To extend your example: struct Class1Compare { bool operator() (const Class1& lhs, const Class1& rhs) const { return lhs.id < rhs.id; } }; std::map<Class1, int, Class1Compare> c2int; It … Read more