I am trying to convert a C++ string to a cstring, or char*. I want the hash function that takes a char* to always be called(after converting from a string). I've been looking at this code for an hour and also searching. No luck.
char* a = "foo";
string b = "foo";
hash(a, 1); // calls the char* hash
hash(b, 1); // calls string hash
int hash(string key, int i){//STRING HASH
char const* cstring = key.c_str();
return hash(cstring, i);//should not be a recursive call but is
}
int hash(char* key, int i){//Cstring HASH
//should get called here
return hash(intKey, i);
}
I hope this is clear enough. It has been a long day! :-p
Something interesting is that char* a and char const* a call the char* method from main but not from the string method. Interesting.
(Posted as answer by request) Change the hash function to
int hash(char const* key, int i)