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
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 '&'
{
//...
}
You should investigate using the STL's TR1 extension namely
Most modern C++ compilers ship with these extensions, hence there is no need to use a non-standard class such as hash_set etc.