Hello, I am implementing a Hash Table based on a given function. I have coded most of it, but whenever I try to add something to the hash table, I get an error code of 139. I've narrowed it down to where it crashes (HashTab.cpp in the add() function), and I would appreciate if someone looked over my code and offered suggestions or a solution to make it not crash anymore. Here is the code:
So just do something like this? HashTab* hashTab = new HashTab();
Something like it.
and Element* elarray = new Element[7];
elarray as defined in the code above is an array of 7 pointers-to-Element. You could change the definition to something like described here, or you could keep it as you previously had it and make those pointers point to objects, or you could just use a normal array of 7 Element objects.
Pointers are still very new to me, and I was under the impression that HasTab* hashTab
would declare and create a valid pointer to use.
It defines a pointer. Given that it is defined at global scope, it is zero-initialized. It is not valid to dereference as it does not point to an existing object.
The thing to remember about pointers is that you shouldn't use them unless you can't get around it.