How to delete the only node in a double linked list?

So yeah, I keep dereferencing a NULL pointer and I'm ashamed. What am I doing wrong?

https://pastebin.com/sjBggMd4
1
2
3
4
5
6
7
        else if (head->next == NULL)
        {
            T output;
            output = head->data;
            delete head; //head is now invalid
            return output;
        }
`head' ends in an invalid state, set it to null.

also, you said that you return T, null may be not be a valid replacement.
Thank you good sir :)
Topic archived. No new replies allowed.