我正在自己实现一个 HashTable 并发现以下错误:
19 template <class key, class value>
20 class HashEntry { ... }
60 template <class key, class value>
61 class HashTable
62 {
63
64 private:
65 size_t _tableSize;
66 HashEntry<key, value>** _table;
67
68 public:
69
70 HashTable(size_t s)
71 {
72 _tableSize = s;
73 _table = (HashEntry<key, value>**) smalloc(s * sizeof(HashTable<key, value>*));
74 }
75
76 void addEntry(HashEntry<key, value>(key k, value v)) <---
77 {
78
79 }
80
...
91 };
93 int main ()
94 {
95 HashTable<int, string> t(100);
96 t.addEntry(HashEntry<int, string>(1, string("a"))); <---
HASH_chaining.cc:96: error: no matching function for call to ‘HashTable<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::addEntry(HashEntry<int, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >)’
HASH_chaining.cc:76: note: candidates are: void HashTable<key, value>::addEntry(HashEntry<key, value> (*)(key, value)) [with key = int, value = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]
乍一看,我找不到任何问题。我认为这与我定义 addEntry 接口的方式有关。
谢谢。