I am getting segmentation fault in this code but i cant figure out why. I know a segmentation fault happens when a pointer is NULL, or when it points to a random memory address.
q = p;
while(q -> link != NULL){
q = q -> link;
}
t = new data;
t -> city = cityName;
t -> latitude = lat;
t -> longitude = lon;
q -> link = t;
This is the error am actually getting in console:
line 33: 2219 Segmentation fault sh "${SHFILE}"
In the
elseclause inDatabase::add, you do not sett->link = NULL, so it is uninitialized.You should add a constructor for
datathat initializes its members, or use the value-initializingnewto ensure that everything is initialized correctly: