I am not too versed in C++, but I had the task of designing and implementing a linked list. This is what I handed in:
template <typename T>
struct Node
{
    Node() : next(nullptr) {}
    Node(T const & val) : next(nullptr), value(val) {}
    Node * next;
    T value;
};
template <typename T>
class LinkedList
{
    public:
        LinkedList()
        {
            begin_ = new Node<T>;
            current_ = begin_;
        }
        ~LinkedList()
        {
            delete begin_;
        }
        void insert(T const & value)
        {
            Node<T> * node = new Node<T>(value);
            node->next = current_->next;
            current_->next = node;
            current_ = current_->next;
        }
        void remove()
        {
            Node<T> * tmp = current_->next;
            if(!end())
            {
                current_->next = current_->next->next;
            }
            delete tmp;
        }
        bool end() const
        {
            return current_->next == nullptr;
        }
        void reset()
        {
            current_ = begin_;
        }
        void advance()
        {
            if(!end())
            {
                current_ = current_->next;
            }
        }
        T get() const
        {
            return current_->next->value;
        }
    private:
        Node<T> * begin_;
        Node<T> * current_;
};
I passed the assignment, but my teacher underlined the delete begin_ in the destructor ~LinkedList() and wrote "This leaks!" next to it. I have been thinking about how delete begin_ could possibly leak but I still do not understand. Can someone please help me with this?
 
     
     
     
    