I'm trying to create a basic linkedList then print next node of head node but i get a runtime error.
class LinkedListNode
{
public:
LinkedListNode* next = NULL;
string data;
LinkedListNode(string data)
{
this->data = data;
}
};
class LinkedList
{
public:
int count = 0;
LinkedListNode *head;
void add(LinkedListNode obj)
{
LinkedListNode* browser = head;
while (browser->next != NULL)
browser = browser->next;
browser->next = &obj;
count++;
}
};
int main()
{
LinkedList list;
list.head = new LinkedListNode("headnode");
LinkedListNode a1("a1");
LinkedListNode a2("a2");
list.add(a1);
list.add(a2);
cout << list.head->next->data << "\n"; // <- HERE ERROR OCCURS 0xC0000005: 0xCCCCCCCC
cout << list.count;
}
Am i doing something wrong i cant figure out the reason of 0xC0000005: 0xCCCCCCCC
User contributions licensed under CC BY-SA 3.0