Reputation: 1720
I'm implementing a HashTable myself and found the following error:
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> >]
At glance, I could't find anything wrong with it. I think it has to do with the way I define the addEntry interface though.
Thanks.
Upvotes: 0
Views: 93
Reputation: 16263
You can't extract things in the parameter list (looks like that's what you're trying to do).
Change your addEntry
function so that its signature is either:
void addEntry(HashEntry<key, value> h)
or
void addEntry(key k, value v)
The second one seems cleaner in my opinion, but if you really want the caller to construct the HashEntry
for some reason, the first one is fine as well.
Upvotes: 3