simple C++ hash_set example

前端 未结 2 1002
旧时难觅i
旧时难觅i 2020-12-31 20:10

I am new to C++ and STL. I am stuck with the following simple example of a hash set storing custom data structures:

#include 
#include 

        
2条回答
  •  爱一瞬间的悲伤
    2020-12-31 20:39

    So close! The last error in your output reveals your hash_trip routine should be declared const:

    size_t operator()(const trip t) const // note the ending 'const'
    {
        //...
    }
    

    You'll probably need to do the same thing for eq_trip. Also, I would recommend passing the arguments to these functions by constant reference to avoid an unnecessary copy of the data you're passing:

    size_t operator()(const trip& t) const // note the '&'
    {
        //...
    }
    

提交回复
热议问题