Hi, I'm a beginners of C++, and I've found something weird error called Segmentation falut <core dumped>. I can't understand why my codes keep making this error. Please help me.
*Whole concept is to put certain number of coals in each carriages of Train.
I put the data in array into nodes and each node are linked by Linkedlist.
[ code ] [ /code ] tags. Simply googling would have told you that a segmentation fault occurs when you attempt to access memory that doesn't belong to your program, for example
1 2 3 4
bool a[4];
a[4]=true;//seg fault - maximum legal index of a is 3
int *b=0;
*b = 10; // seg fault, can not dereference null pointer
You are probably dereferencing an uninitialized pointer or attempting to access an array index that is out of bounds somewhere. Seeing as you have a linked list there, probably the former. Best way to figure out what's wrong would be learning how to use a debugger.
#0 0x0804880b in john_linked_5::LinkedList::list_head_insert (
this=0xb7e9bff8, head_ptr=0xb7ebc2c0, entry=-1209285952) at 04.cpp:117
Which is talking about the values passed to the function
void LinkedList::list_head_insert(node* head_ptr, node::value_type entry)
entry has the value -1209285952 so it looks to me like you're passing in a bad value from the calling line, which is this line: