我有以下课程:
class UnionFuzzySet : public FuzzySet
{
public:
UnionFuzzySet();
void addActivatedFuzzySet(const ActivatedFuzzySet &set);
double getValue(double value);
private:
QSet<ActivatedFuzzySet> subConclusions;
};
方法addActivatedFuzzySet(...):
void UnionFuzzySet::addActivatedFuzzySet(const ActivatedFuzzySet &set)
{
this->subConclusions << set;
}
它不适用于编译错误:
c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore \ qhash.h:882:ошибка:C2665:'qHash':16个重载中没有一个可以转换所有参数类型 c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(62):可能是'uint qHash(char)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(63):或'uint qHash(uchar)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(64):或'uint qHash(signed char)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(65):或'uint qHash(ushort)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(66):或'uint qHash(short)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(67):或'uint qHash(uint)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(68):或'uint qHash(int)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(69):或'uint qHash(ulong)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(77):或'uint qHash(long)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(78):或'uint qHash(quint64)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(86):或'uint qHash(qint64)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(87):或'uint qHash(QChar)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(88):或'uint qHash(const QByteArray&amp;)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(89):或'uint qHash(const QString&amp;)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(90):或'uint qHash(const QStringRef&amp;)' c:\ QtSDK \ Desktop \ Qt \ 4.8.0 \ msvc2010 \ include \ QtCore / qhash.h(91):或'uint qHash(const QBitArray&amp;)' 在尝试匹配参数列表'(const ActivatedFuzzySet)'
时请告诉我,我在哪里弄错了?
答案 0 :(得分:6)
QSet
在里面使用哈希表。但是要在哈希表中存储项目,您应该能够计算项目的哈希值。 qHash
函数确实计算项目的哈希值。
正如您所看到的,它是一些预定义的重载,允许您计算标准类型的哈希值,但如果您想存储ActivatedFuzzySet
,则应定义接受{{1}的函数qHash
就像那样:
ActivatedFuzzySet
答案 1 :(得分:2)
所有数据类型都不能在qhash中设置为模板。 请阅读qt文档页面:http://developer.qt.nokia.com/doc/qt-4.8/qset.html#details
如果您设置指向您的类型的指针而不是类型,那么它应该没问题