Player* HashTable::retrieve(char * key, Player& aPlayer)
//calculate the retrieval position (the index of the array)
size_t index = calculateIndex(key);
//search for the data in the chain (linked list)
node * curr = table[index];
if(strcmp(key, id) == 0)
//find match and return the data
aPlayer = table[index]->item;
pt = &aPlayer;
curr = curr->next;
Here I'm calling the retrieve and I need to return a pointer of that object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Player* PlayerDB::FetchPlayer(char* name)
Player* info = new Player();
out << "Fetching player " << "\"" << name << "\" -- ";
out << "Success!" << endl;
out << "Failed." << endl;
I do have a few observations.
1. retrieve() takes a reference to a Player and return that player if it existed. You have two parallel objects representing any given player; one in the hash, one copied from that hash. Why?
2. If you're using strings, why not use the string class? Having chosen to use C strings, you should be passing constcharchar* around, not char*.
3. Why implement your own linked list when you can use the standard one?
I've been told I need to return a reference of the object in my retrieve function