2
votes

I have following class:

class UnionFuzzySet : public FuzzySet
{
public:
    UnionFuzzySet();
    void addActivatedFuzzySet(const ActivatedFuzzySet &set);
    double getValue(double value);

private:
    QSet<ActivatedFuzzySet> subConclusions;
};

And method addActivatedFuzzySet(...):

void UnionFuzzySet::addActivatedFuzzySet(const ActivatedFuzzySet &set)
{
    this->subConclusions << set;
}

It doesn't work with compiling error:

c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore\qhash.h:882: ошибка: C2665: 'qHash' : none of the 16 overloads could convert all the argument types c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(62): could be 'uint qHash(char)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(63): or 'uint qHash(uchar)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(64): or 'uint qHash(signed char)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(65): or 'uint qHash(ushort)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(66): or 'uint qHash(short)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(67): or 'uint qHash(uint)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(68): or 'uint qHash(int)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(69): or 'uint qHash(ulong)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(77): or 'uint qHash(long)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(78): or 'uint qHash(quint64)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(86): or 'uint qHash(qint64)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(87): or 'uint qHash(QChar)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(88): or 'uint qHash(const QByteArray &)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(89): or 'uint qHash(const QString &)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(90): or 'uint qHash(const QStringRef &)' c:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtCore/qhash.h(91): or 'uint qHash(const QBitArray &)' while trying to match the argument list '(const ActivatedFuzzySet)'

Please, tell me, where have I made a mistake?

2

2 Answers

6
votes

QSet uses hash table inside. But to store item in hash table, you should be able to calculate item's hash. qHash function does calculate hash for item.

As you can see, it is some predefined overloads, that allow you to calculate hash for standard types, but if you want to store ActivatedFuzzySet you should define function qHash that accepts your ActivatedFuzzySet, like that:

uint qHash(const ActivatedFuzzySet& value)  
{
    //calculate hash here
}
2
votes

all data type can t be set as template in a qhash. please, read the qt documentation page : http://developer.qt.nokia.com/doc/qt-4.8/qset.html#details

If you set a pointer to your type instead of the type it should be ok