More specifically, I am wondering why we use pointers in a typical linked list implementation. Are there any problems that the following implementation of a Node might cause?
template <typename T>
class Node {
T data;
Node<T>& next;
Node<T>& prev;
};
Is there some reason we should use pointers here instead of references?
You can’t set references after creating them, which makes a non-mutable linked-list implementation somewhat tricky. (You’d need to wrap the references in objects that you can re-crate when you want to change the reference).
There’s also no way to set a NULL value on a reference, so representing the ends of your list would require some imagination.
Probably better to stick to pointers in a linked list, or even better, use
std::list<>.