When I call the default constructor for my class LinkedList I attempt to assign values to the head node of the linked list before any other operations occur. I have isolate the error, via debugging, to the instructions in the default constructor. As soon as
head -> next = NULL;
head -> RUID = 0;
head -> studentName = "No Student in Head";
are called the program crashes. This occurs when I call the default constructor in main. Here is my class declaration and my struct declaration along with the default constructor:
struct Node
{
string studentName;
int RUID;
Node* next;
};
class LinkedList
{
private:
// Initialize length of list
int listLength;
public:
// Head of the list, which points to no data yet
Node *head;
LinkedList();
bool insertNode(Node* newNode, int position);
int generateRUID();
};
LinkedList::LinkedList()
{
head -> next = NULL;
head -> RUID = 0;
head -> studentName = "No Student in Head";
listLength = 0;
}
I believe this all of the relevant code to this issue. If someone could shed light on this it would be much appreciated.
headmust be initialized before all of the others. It's an empty reference at the start ofLinkedList::LinkedList.