monkey doodle
monkey doodle

Reputation: 700

Unhandled exception at 0x010F2F1C in program.exe: 0xC0000005: Access violation reading location 0xCCCCCCD0

I can't seem to figure out why I am getting such an error: I am trying to implement linked list and do an insertion to a list, however in my third line of code I'm getting access errors. Error:

Unhandled exception at 0x010F2F1C in program.exe: 0xC0000005: Access violation reading location 0xCCCCCCD0.

in my main ()

list2.InsertNode(1, test);
cout << "cout << list2 " << endl;
cout << list2 << endl;

insert method

void NodeSLList::InsertNode(int nodeNum, const IntNode &node)
{


    IntNode *prevNode = head;
    for (int i = 1; i < nodeNum; i++)
        prevNode = prevNode->next;

    IntNode * insert;
    insert = new IntNode(node);
    prevNode->next = insert;

    insert->next = prevNode->next->next;

}

At the third line the error occurs cout << list2 << endl;( "<<" is overload to output the linked list)

ostream & operator<<(ostream & output, NodeSLList & list)
{
    int size;
    size = list.GetSize();
    output << "List: ";
    for (int i = 1; i <= size; i++)
    {
        output << list.RetrieveNode(i).data<<"    ";
    }
    return output;
}

More specifically, when << operator is called, and calls the GetSize method, the error occurs here:

    p = p->next;

getsize method:

int NodeSLList::GetSize()
{
    // check to see if the list is empty. if 
    // so, just return 0
    if (IsEmpty()) return 0;

    int size = 1;
    IntNode *p = head;
    // compute the number of nodes and return
    while (p != tail)
    {
        // until we reach the tail, keep counting
        size++;
        p = p->next;
    }
    return size;
}

Upvotes: 0

Views: 2938

Answers (1)

Werner Henze
Werner Henze

Reputation: 16726

0xcc or 0xcccccccc is the pattern that MSVC uses to initialize local variables not explicitly initialized by your program (if /GX was set).

If your p->next fails with an access to 0xCCCCCCD0 this shows that your pointer p was 0xCCCCCCCC. Look at the code that you did not post here that builds your list and check that you always set next to a proper value.

Upvotes: 1

Related Questions