我正在尝试QSet
用于存储函数指针列表。有关更多详细信息,请参阅此代码。问题是这段代码不能由 gcc/mingw 编译。MSVC 正常编译它。我究竟做错了什么?
typedef intptr_t (*UikHook)(intptr_t);
...
typedef struct
{
QSet<UikHook>* qsetSubscribers;
//QMutex* qmutexHook;
} THookableEvent;
...
THookableEvent* p = qmapHooks_.value(name);
if (p->qsetSubscribers == 0)
p->qsetSubscribers = new QSet<UikHook>();
p->qsetSubscribers->insert(hookProc);
error: no matching function for call to ‘qHash(long int (* const&)(long int))’
也许,我应该像文档中所说的那样为类型声明operator==
和函数,但我不知道该怎么做,因为当我声明时,我收到以下错误:qHash()
UikHook
opertator==
inline bool operator==(const UikHook &e1, const UikHook &e2)
error: ‘bool operator==(intptr_t (* const&)(intptr_t), intptr_t (* const&)(intptr_t))’
must have an argument of class or enumerated type
PS 我正在使用 Qt 5.8、gcc 6.2、msvc2015
更新:通过将 QSet 替换为 QVector 解决。