I see no reason for it to be public
I see no reason for it to be public
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
you could pass the hash generator as a template parameter (that would default to some predefined object).
I also created an method VALUETYPE getItem( const string& key ) const; inside the public
However, when I tried to compile it the HastTableTest.cpp, it shows I have 2 errors
Here is my code from the method getItem
Also for the method getIndex, Do you think it should return res instead of returning *key % 20?Code:template <typename KEYTYPE, typename VALUETYPE> VALUETYPE HashTable<KEYTYPE,VALUETYPE>::getItem( const string& key ) const { VALUETYPE value; return value; }
Last edited by joenching; 05-02-2005 at 01:29 PM.
You need to use the same kind of code to get elements out as you use to store them
Code:template <typename KEYTYPE, typename VALUETYPE> VALUETYPE HashTable<KEYTYPE,VALUETYPE>::getItem( const string& key ) const { int position = myHashFunction( key ); // compute a position // now do domething with hashTable[position] // bearing in mind that there could be any number of entries at this hash position // see your example output. }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.