I couldn't find anything similar to this anywhere. I have an array of pointers to objects (a linked list) for a hash table:
LinkList * table[TABLE_SIZE];
for (int i = 0; i < TABLE_SIZE; i++)
table[i] = NULL;
In one of my functions for my hash table class, there I need to call the one of the functions on the LinkList object in the table array. I'm calling it as such:
void HashMap::add_customer(string first, string last, string phone) {
int hash = get_hash(phone);
if (table[hash] == NULL) {
table[hash] = new LinkList;
}
table[hash]->add_customer(first, last, phone); // I HATE THIS LINE
}
Everything compiles fine, but when I execute the table[hash]->add_customer() line in runtime, I get a Segmentation Fault error. When this line is commented out, I get no errors, but obviously, I can't add any customers to my hash table. Is this not the right syntax?
HashMap::add_customeris called.tablethat you have shown, it is not initialized to allNULL's, so do you do it later? Why not useLinkList *table[TABLE_SIZE] = {}?