on-internet
← Community

Moving from C, how can I implement a doubly linked list in C++ using C++ features?

Stack Overflow ·

I'm moving from C to C++ and I'm trying to avoid using C practices in C++. It is said that raw pointers are a C feature, and that in C++ I should use smart pointers instead, yet every example I have seen online for implementing a doubly-linked list starts something like this: class DoublyLinkedList { struct Node { int data; Node* prev; Node* next; }; Node* head; Node* tail; ... }; I struggle to find an elegant way to implement this with smart pointers. I could implement it using shared pointers, but I heard that these should be seldom used and that I should attempt implementing using unique_pt

Comments

Sign in or sign up to comment and upvote.

No comments yet.