如果unordered_map直接使用QString作为键值,C++会报错,报错内容如下:
error C2338: The C++ Standard doesn't provide a hash for this type.
这时候需要为QString写一个hash,
#include#include namespace std { template<> struct hash { std::size_t operator()(const QString& s) const noexcept { return (size_t)qHash(s); } }; }
之后执行就不会报错了。



