I have three structs being used:
struct namedPlace{
string name, key;
double lat, lon, interdist, interref;
intersections * inter;
namedPlace * next;
namedPlace(){next = NULL;}
namedPlace(string k, string n, double la, double lo, double c, double i, namedPlace * ne){
key = k;name = n; lat = la; lon = lo;interref=c; interdist = i; next=ne;}
};
struct Node{
namedPlace * head;
Node(){head=NULL;}
void insertInNode(namedPlace * place)
{ if(head==NULL) cout<<"NULL";
namedPlace * hold = head;
head = place;
place -> next = hold; }
};
struct haash{
Node ** nArr;
haash(){nArr=NULL;}
void HashMap() {
nArr = new Node*[30000];
}
void insertInHash(const int entry, namedPlace *in)
{ nArr[entry]->insertInNode(in); }
};
And in main I have:
haash h;
h.HashMap();
for(int i = 0; i <20; i++)
{
//code to get values to insert in node
namedPlace * np = new namedPlace(postal, namePlace, lattt, longgg, intersectReff, distanceToIntersection,NULL);
int hashVal = h.hasher(np->key);
h.insertInHash(hashVal,np);
}
The program breaks (run time error) when I try to check if head is NULL in the Node struct. I'm led to believe this is happening because there is some undefined behavior around head, but am confused because I believe I initialize it to NULL with my constructor. I am told that nArr[entry] is CDCDCDCD, and as it has been pointed out, this is due to uninitialized heap memory. How do I properly initialize it?