title: 0xC0000005: Access violation writing location 0x00000004.'
body: <p>I created this linked list class to use it in my work but I have this exception 'First-chance exception at 0x003216D2 in game.exe: 0xC0000005: Access violation writing location 0x00000004.' and it is coming from erase function can someone show me how can fix it and explain what it the problem </p>
  
  <pre><code>#ifndef LINKEDLIST_HPP
  #define LINKEDLIST_HPP
  
  
  #include &lt;vector&gt;
  #include &lt;cassert&gt;
  
  template&lt;typename T&gt;
  class Linkedlist
  {
  private:    
      // The basic doubly linked Linkedlist node.
      // Nested inside of Linkedlist, can be public
      // because the Node is itself private
      struct Node
      {
          T  _data;
          Node   *_prev;
          Node   *_next;
  
          Node( const T &amp; d = T(), Node * p = NULL, Node * n = NULL )
              : _data( d ), _prev( p ), _next( n ) { }
  
  
          // Rvalue   
          Node(Node &amp;&amp; n)
          {
              _data = std::move(n._data);
              _prev = std::move(n._prev);
              _next = std::move(n._next);
          }
  
          // = operator
          Node&amp; operator =(Node &amp;&amp; n)
          {
              _data = std::move(n._data);
              _prev = std::move(n._prev);
              _next = std::move(n._next);
              return *this;
          }
      };
  public:
      class LinkedListIter : public std::iterator&lt;std::forward_iterator_tag , T , int&gt;
      {
          Node* _node;
      public:
          LinkedListIter(Node* p=nullptr) : _node(p){}
          ~LinkedListIter(){}
  
          Node* getNode(){return _node;}
  
          T operator * () { return _node-&gt;_data; }
          LinkedListIter &amp; operator ++()
          {
              _node = _node-&gt;_next;
              return *this; 
          }
  
          LinkedListIter operator ++(int)
          {
              LinkedListIter  retVal = *this;
              ++this;
              return retVal;
          }
          bool operator &lt; (LinkedListIter const&amp; rhs) const
          { 
              return _Node &lt; rhs._Node; 
          }
          bool operator != (LinkedListIter const&amp; rhs) const
          {
              return _Node != rhs._pNode;
          }
          bool operator == (LinkedListIter const&amp; rhs) const 
          {
              return _Node == rhs._Node;
          }
      };
  
  
  
      Linkedlist( )
      { init(); }
  
      ~Linkedlist()
      {
          clear();
          delete _head;
          delete _tail;
      }
  
      Linkedlist(const Linkedlist &amp; rhs)
      {
          init( );
          *this = rhs;
      }
  
      const Linkedlist &amp; operator= (const Linkedlist &amp; rhs)
      {
          if( this == &amp;rhs )
              return *this;
          clear( );
          for(const_iterator itr = rhs.begin(); itr != rhs.end( ); ++itr)
              push_back(*itr);
          return *this;
      }
  
      // Return iterator representing beginning of Linkedlist.
      // Mutator version is first, then accessor version.
      LinkedListIter begin()
      { return LinkedListIter(_head-&gt;_next);}
  
  
      // Return iterator representing endmarker of Linkedlist.
      // Mutator version is first, then accessor version.
      LinkedListIter end()
      { return LinkedListIter(_tail); }
  
  
      // Return number of elements currently in the Linkedlist.
      int size() const
      { return _size; }
  
      // Return true if the Linkedlist is empty, false otherwise.
      bool empty() const
      { return size() == 0; }
  
      void clear()
      {
          while( !empty() )
              pop_front();
      }
  
      // front, back, push_front, push_back, pop_front, and pop_back
      // are the basic double-ended queue operations.
      T &amp; front()
      //{ return *begin( ); }
      {return _head-&gt;_next.data}
      const T &amp; front() const
      { return *begin(); }
  
      T &amp; back( )
      { return *--end(); }
  
      const T &amp; back() const
      { return *--end(); }
  
      void push_front(const T &amp; x)
      { insert( begin(), x ); }
  
      void push_back(const T &amp; x)
      { insert( end(), x ); }
  
      void pop_front()
      { erase(begin()); }
  
      void pop_back()
      { erase(--end()); }
  
      // Insert x before itr.
      LinkedListIter insert(LinkedListIter&amp; itr, const T &amp; x)
      {
          Node *p = new Node(x,itr.getNode()-&gt;_prev,itr.getNode());
          _size++;
          return LinkedListIter(p-&gt;_prev = p-&gt;_prev-&gt;_next = new Node(x, p-&gt;_prev, p));
      }
  
      // Erase item at itr.
      LinkedListIter  erase(LinkedListIter itr)
      {
          Node *p = itr.getNode();
          LinkedListIter retVal(p-&gt;_next);
          p-&gt;_prev-&gt;_next = p-&gt;_next;
          p-&gt;_next-&gt;_prev = p-&gt;_prev;
          delete p;
          _size--;
  
          return retVal;
  
  
      }
  
      LinkedListIter erase(LinkedListIter start, LinkedListIter end)
      {
          for(iterator itr = start; itr != end;)
              itr = erase(itr);
  
          return end;
      }
  
  private:
      int   _size;
      Node *_head;
      Node *_tail;
  
  
  
  
      void init()
      {
          _size = 0;
          _head = new Node;
          _tail = new Node;
          _head-&gt;_next = _tail;
          _tail-&gt;_prev = _head;
      }
  };
  
  #endif
  </code></pre>