jeudi 20 septembre 2018

I have a Thread 1:EXC_BAD_ACCESS (code =1, address=0x8) error. I think its due bad memory management. What are some steps I can take to prevent this?

Here is my code:

template<class T>
void list<T>::addEnd(T input) {
    node<T> *tempNode = new node<T>;
    node<T> * current = head;
    while (current->next == nullptr) {
        current = current->next;
    }
    tempNode->data = input;
    current->next = tempNode;
    tempNode->next = nullptr;
    tempNode->prev = current;
    tail = tempNode;
 }

The error occurs at the while(current->next == nullptr) line. I'm trying to implement a doubly linked list.

Aucun commentaire:

Enregistrer un commentaire