我正在使用Qt,我想声明以下容器:
QMap<QUrl , QSet<ClassSharedPtr> > map;这里的ClassSharedPtr是类" class“的boost共享ptr。
typedef boost::shared_ptr<const Class> ClassPtr;在添加头文件#include后,我收到以下错误:
error: no matching function for call to ‘qHash(const boost::shared_ptr<const Class>&)’发布于 2015-10-20 17:14:36
QSet的value数据类型必须是可赋值的数据类型。此外,该类型必须提供operator==(),并且该类型的命名空间中还必须有一个qHash()函数,该函数返回values类型的参数的哈希值。
因此,您应该为boost::shared_ptr<const Class>实现qHash()函数。
namespace boost {
uint qHash(const boost::shared_ptr<const Class> &key, uint seed = 0)
{
const Class *ptr = key.get();
return uint(ptr) ^ seed;
}
}https://stackoverflow.com/questions/33228402
复制相似问题