I'm working on a templated generic linked list in C++, and I'm having trouble with the push() method. I think I know the problem, but I can't figure out a solution. Here is the push method I have.
template <class T> void DLL<T>::pushFront(T value) {
Node<T> node(value);
temp = node;
temp->setPrev(*head);
temp->setNext(*(head->getNext()));
head->setNext(*temp);
temp->getNext()->setPrev(*temp);
this->length++;
}
After pushing some integers into the list, traversing through the list and printing off the values results in printing off numbers that appear to be random space in memory. I think this is because of something to do with the node variable being destroyed after the push function returns. Anyone know why this isn't working? All of the setNext/Prev() and getNext/Prev() functions work correctly in my other tests. I'm stumped...
edit*
The variables head and temp are globals of type Node< T >*