[Qt-interest] qhash - user defined key type
Yifei Li
yifli at mtu.edu
Thu Aug 20 21:43:00 CEST 2009
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
More information about the Qt-interest-old
mailing list