Exception thrown at 0x53F3D9CB (ucrtbased.dll) in ConsoleApplication17.exe: 0xC0000005: Access violation reading location 0xDDDDDDCD. occurred

-2

I am trying create my own Singly Linked list template. When I try to remove an element from the start it works fine for the first time, when it runs for second time, it get lost some time. I do not know what happens.

1: remove 2: reset

are causing the same error.

    bool reset() {
        Node<TYPE>* currentPtr = listStart;
        if (!isEmpty()) {
            while (currentPtr->nextPtr != nullptr) {
                currentPtr = currentPtr->nextPtr;
                listStart = currentPtr;
                delete currentPtr->nextPtr;

            }
            delete currentPtr->nextPtr;
            return true;
        }
        else
            return false;
    }
    bool remove() {
        if(!isEmpty()){
            Node<TYPE>* temp = listStart;
            listStart = temp->nextPtr;
            delete temp->nextPtr;
            return true;
        }
        else {
            std::cout << "List is Already Empty";
            return false;
        }
    }
private:
    Node<TYPE>* listStart;
    };```
c++
pointers
asked on Stack Overflow May 15, 2019 by foragerDev

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0