How can I use a C++ unordered_set for a custom class?

后端 未结 4 1847
逝去的感伤
逝去的感伤 2021-02-04 07:32

How can I store objects of a class in an unordered_set? My program needs to frequently check if an object exists in this unordered_set and if it does,

4条回答
  •  故里飘歌
    2021-02-04 07:40

    You need to implement a custom hash function (I'd suggest using the function in the Boost library) to do this. C++ allows you to save pointers to objects of a class using unordered_set. For most purposes, that should do the trick.

提交回复
热议问题