program error

this code, which is directly copypaste from the book itself, is appended to Blob.h., producing the above error.

template <class> struct std::hash;

class Sales_data {
    friend struct std::hash<Sales_data>;
    // other members
};

// specialization
namespace std{
template <>
struct hash<Sales_data> {
    typedef size_t result_type;
    typedef Sales_data argument_type;

    size_t operator()(const Sales_data& s) const;
};

size_t hash<Sales_data>::operator()(const Sales_data& s) const
{
    return hash<string>()(s.bookNo) ^
           hash<unsigned>()(s.units_sold) ^
           hash<double>()(s.revenue);
}

}

You cannot do a forward declaration of a class outside of its namespace, you need to do this:

namespace std {
template <class> struct hash;
}

I think that will solve it.

Also, I'm pretty sure you need the template <> on the definition of the hash's operator() for your full specialization.

Edited 2 Years Ago by mike_2000_17: added note

"Also, I'm pretty sure you need the template <> on the definition of the hash's operator() for your full specialization."

don't work also, I end up defined it inside of the class itself.

don't work also, I end up defined it inside of the class itself.

Yeah, that's why I wasn't sure (without checking), because I always just define it within the class.

This question has already been answered. Start a new discussion instead.