Hello,
I am trying to implement hash table functionality using templates.
I need to declare the hash table element as a struct or class inside the HTable template...
I get following compilation error. Why does compiler fail to associate <RecordType> with HTElement::entry ?
driver.cpp:131: instantiated from here
./htable.icc:66: error: no match for 'operator=' in '((hashtable::HashTable<Cont
act>*)this)->hashtable::HashTable<Contact>::data[index].hashtable::HashTable<Con
tact>::HTElement::entry = entry'
./contact.hpp:71: note: candidates are: Contact& Contact::operator=(Contact&)
./htable.icc: In member function `void hashtable::HashTable<RecordType>::find(st
d::string, bool&, RecordType&) const [with RecordType = Contact]':
driver.cpp:164: instantiated from here
./htable.icc:117: error: no match for 'operator=' in 'result = ((const hashtable
::HashTable<Contact>*)this)->hashtable::HashTable<Contact>::data[index].hashtabl
e::HashTable<Contact>::HTElement::entry'
here is the code I have..
template <class RecordType>
class HashTable
{
public:
//Member Constant
static const std::size_t CAPACITY = 20;
//Constructor
HashTable();
void insert(const RecordType& entry, std::string key);
void remove(std::string key);
//Constant Member Functions
bool is_present(std::string key) const;
void find(std::string key, bool& found, RecordType& result) const;
std::size_t size() const {return used;}
void toArray(RecordType* array, int size) const;
private:
//Member Constants
static const int NEVER_USED = -1;
static const int PREVIOUSLY_USED = -2;
static const int IN_USE = 1;
//Member Variables
typedef struct HTElement_tag {
public:
RecordType entry;
std::string key;
int status;
}HTElement;
HTElement data[CAPACITY];
std::size_t used;
//Helper Functions
std::size_t hash(std::string key) const;
std::size_t next_index(std::size_t index) const;
void find_index(std::string key, bool& found, std::size_t& index) const;
bool never_used(std::size_t index) const;
bool is_vacant(std::size_t index) const;
};