现象:在32位Linux、Gcc 4.4.6 版中编译代码报这个错误:
/usr/lib/gcc/i686-redhat-linux/4.4.6/../../../../include/c++/4.4.6/backward/hashtable.h:590: error: no match for call to '(const __gnu_cxx::hash<long long unsigned int>) (const long long unsigned int&)'
使用到的代码:
#include <ext/hash_map>
hash_map<uint64_t, uint64_t> m_hmUseBuff;
bool CTimerBrd::Delete(void* dItem)
{
// 元素有效性验证
TimerItem* pItem = reinterpret_cast<TimerItem*> (dItem);
#ifdef USE_SPINLOCK
pthread_spin_lock(&m_spinlock);
#else
m_mutex.Lock();
#endif
// 判断传入的handle是否已经被删除 或者位置错误
if((NULL == dItem)
|| (pItem->uiPosition > MAXTIMERCNT)
|| (pItem->Checksum != (pItem->uiPosition ^ pItem->uiCycle)
|| (m_hmUseBuff.end() == m_hmUseBuff.find((uint64_t)dItem))))
{
// 校验验证
m_pOwner->m_stTimerStat.ulKillFail++; //删除失败统计
#ifdef USE_SPINLOCK
pthread_spin_unlock(&m_spinlock);
#else
m_mutex.Unlock();
#endif
if (m_pOwner->m_stTimerStat.ulKillFail % 5000 == 1) //日志打印频率控制
{
LOGGER_ERROR(m_pLogger, " KillTimer时指定了无效的参数. Item = [" << dItem << "] 校验失败");
}
return false;
}
...................................................
在代码中使用到了hash_map的一个查找find,。
解决方法:
在hash_map 中加入支持64位的类型结构体,就能编译通过, eg:(这是为什么呢??)
template<>
struct hash<long long int>
{
size_t
operator()(long long int _x) const
{
return _x;
}
};
template<>
struct hash<unsigned long long int >
{
size_t
operator()(unsigned long long int _x) const
{
return _x;
}
};