By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,197 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,197 IT Pros & Developers. It's quick & easy.

Template: Structure inside class.

P: 1
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;
};
Jun 14 '07 #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,197
I have no idea.

I compiled your code with Visual Studio.NET 2005 and got no errors.

What kind of compiler are you using???
Jun 14 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.