[Qt-interest] qhash - user defined key type
Yifei Li
yifli at mtu.edu
Thu Aug 20 22:30:55 CEST 2009
Thank you for the reply.
I did provide an implementation like yours. The implementation was omitted to make the minimal example look concise :)
Anything else you can think of?
Yifei
----- Original Message -----
From: "Jonas Gehring" <jonas.gehring at boolsoft.org>
To: qt-interest at trolltech.com
Sent: Thursday, August 20, 2009 4:08:09 PM GMT -05:00 US/Canada Eastern
Subject: Re: [Qt-interest] qhash - user defined key type
Hi,
You need to provide an implementation of qHash(const Test::Foo&), like
inline uint qHash(const Foo& f) {
return qHash(f.id());
}
This one is using qHash(int), as provided by Qt itself.
Regards,
Jonas
On Thursday 20 August 2009 21:43:00 Yifei Li wrote:
> Here is the problem I'm having with QHash right now ( Below is a minimal
> example that will reproduce my problem)
>
> /** Header file from some third-party library */
>
> namespace Test {
> class Foo{
> public:
> Foo(id);
> int id() const { return m_id; }
> private:
> int m_id;
> };
> }
>
> /** My header file */
>
> using namespace Test;
>
> class Bar{
> public:
> void init()
> {
> Foo f(1);
> indicators[f] = false;
> }
> private:
> QHash<Foo, bool> indicators;
> };
>
> // overload operators so that Foo can be used as a key type
> inline bool operator==(const Foo& f1, const Foo&f2)
> inline uint qHash(const Foo& f);
>
> /** main.cpp */
> int main
> {
> Bar b;
> b.init();
> return 0;
> }
>
> /** Failed to compile the above code */
> ERROR: no matching function for call to ‘qHash(const Test::Foo&)’
>
> What should I do to get rid of the error? thanks
>
>
> Yifei
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list