我在我的几个成员函数中有这一行,它们工作得很好,除了这个
template<typename K, typename V>
bool HashTable<K, V>::match( const std::pair<K, V> &kv ) const
{
auto & whichList = theLists[ myhash( kv.first ) ];
auto itr = whichList.begin();
for(; itr != whichList.end(); itr++)
{
if( (itr->first == kv.first) && (itr->second == kv.second) )
return true;
}
return false;
}
以下是我遇到的错误
g++ -std=c++11 -Wall -pedantic main.cpp -o main
In file included from main.cpp:1:0:
HashTable.h: In instantiation of ‘bool cop4530::HashTable<K, V>::match(const std::pair<_T1, _T2>&) const [with K = std::basic_string<char>; V = int]’:
main.cpp:27:20: required from here
HashTable.h:119:49: error: no matching function for call to ‘cop4530::HashTable<std::basic_string<char>, int>::myhash(const std::basic_string<char>&) const’
auto & whichList = theLists[ myhash( kv.first ) ];
^
HashTable.h:119:49: note: candidate is:
HashTable.h:276:9: note: size_t cop4530::HashTable<K, V>::myhash(const K&) [with K = std::basic_string<char>; V = int; size_t = long unsigned int] <near match>
size_t HashTable<K, V>::myhash(const K & k)
^
HashTable.h:276:9: note: no known conversion for implicit ‘this’ parameter from ‘const cop4530::HashTable<std::basic_string<char>, int>* const’ to ‘cop4530::HashTable<std::basic_string<char>, int>*’
makefile:2: recipe for target 'run.x' failed
make: *** [run.x] Error 1
知道为什么会这样。就像我说的那样,这条线可以用于我称之为的其他任何东西。