Okay, I'm trying to make a quick little class to work as a sort of hash table. If I can get it to work then I should be able to do this:
StringHash* hash = new StringHash;
hash["test"] = "This is a test";
printf(hash["test"]);
And it should print out "This is a test".
It looks like I have 2 problems at this point. Firstly I did this:
const char* operator[](const char* key) {
for(int i = 0; i < hashSize; ++i) {
if(strcmp(hkeys[i], key) == 0) {return values[i];}
}
return NULL;
}
But when I try to look up a value the compiler complains that
error: invalid types `StringHash*[const char[5]]' for array subscript
Secondly operator[]= does not appear to be the correct syntax here. The only other thing I could find was &operator[] but I don't think that will work since I have to code the lookup procedure??? (Isn't that syntax just used to return an array item reference?)
Is what I'm trying to do here even possible? Any advice appreciated. :)
Seems to be some confusion about what I'm trying to do. I'll post my code:
Finished product after all the help: