use*_*154 0 c++ hash stl hashtable
我尝试过使用#include<hash_map>和#include <hash_set>我仍然得到相同的错误.
这是我的代码:
void HashTable_chaining::remove( const string & x )
{
int hash_index = hash( x, theLists.size( ) ) ;
list<string>& whichList = theLists[ hash_index ];
// search to make sure element not present
for(list<string>::iterator itr=whichList.begin();itr!=whichList.end();itr++) {
if(*itr==x) {
theLists[hash_index].erase(itr);
return;
}
}
// element not found - so nothing to remove
}
Run Code Online (Sandbox Code Playgroud)
我的错误是:
Error 8 error C2872: 'hash' : ambiguous symbol c:\users\aaron johnson\desktop\program 5(johnson- noakes)\program 5(johnson- noakes)\chaining.cpp 32 1 Program 5(Johnson- Noakes)
Run Code Online (Sandbox Code Playgroud)
我有8个这样的错误.有什么建议?如何找出必须包含哪些标头才能使用哈希?
哈希是你自己的功能吗?如果是这样,请尝试将其放在您自己的命名空间中,然后调用函数
int hash_index = yournamespace::hash( x, theLists.size() );
Run Code Online (Sandbox Code Playgroud)
如果你想使用std :: hash:它是在.中定义的
#include <functional>
Run Code Online (Sandbox Code Playgroud)