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.

"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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.