title: When Class deconstructor is called, std::string throws an error
body: <p>I am new to coding, so please forgive me if this question seems stupid. I was writing my own List class to get a better understanding of how Lists are structured, but I ran into an issue. I dynamically allocated my list as I added more items to it, and the deconstructor on my program ran just fine with ints. However, as I was testing with std::string, I ran into an issue. It keeps throwing exceptions after my deconstructor is called(, even though (I'm fairly certain) I deleted the memory I allotted alone, and not theirs (read access violation).</p>
  
  <p>I've tried using smart pointers instead of deleting the allocated memory in my deconstuctor, but that ends up having the same issue. Looking online, all I can seem to find is, "only delete with deconstructors," and, "don't have exception handling in deconstructors." Both of which are not even issues with what I've written.</p>
  
  <p>Here is firstly, the relevant code (in my mind) to solving this.</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;iostream&gt;
  using std::cout;
  using std::cin;
  using std::string;
  
  template &lt;class type&gt;
  class List
  {
      struct Node
      {
          type data;
          Node* next;
      };
  
  public:
  
      List();
  
      ~List();
  
      void addToList(type var);
  private:
  
      Node head;
      Node *last, *lastAcc;
  
      unsigned int length, prevPos;
  };
  
  template &lt;class type&gt;
  List&lt;type&gt;::~List()
  {
      Node *prevPtr;
      lastAcc = head.next;
  
      while (lastAcc-&gt;next) // While the next pointer leads to something
      {
          // Go to that something, and delete the item you were on
  
          prevPtr = lastAcc;
          lastAcc = lastAcc-&gt;next;
          delete prevPtr;
      }
  
      delete lastAcc;
  }
  
  
  template &lt;class type&gt;
  void List&lt;type&gt;::addToList(type var)
  {
      if (length)
      {
          last-&gt;next = new Node;
          last = last-&gt;next;
          last-&gt;data = var;
      }
      else
      {
          head.data = var;
      }
  
      lastAcc = last;
      prevPos = length++;
  }
  
  template &lt;class type&gt;
  List&lt;type&gt;::List()
  {
      head.next = 0;
      prevPos = 0;
      lastAcc = last = &amp;head;
      length = 0;
  }
  
  int main()
  {
      string boi[] = { "Today is a good day", "I had an apple", "It tasted delicious" };
  
      List&lt;string&gt; multiString;
  
      for (int i = 0; i &lt; 3; i++)
      {
          multiString.addToList(boi[i]);
      }
      return 0;
  }
  </code></pre>
  
  <p>I expected the code to run just fine, and if I made an error, I thought the error would show up on my code. Not on std::string. Any help would be greatly appreciated.</p>
  
  <p>[Edit] On an added note, [lastAcc] is abbreviated for last accessed; it's just something I implemented to make going through the lists faster than just having to start from 0 every time. [prevPos] shows the position of [lastAcc] in the list. Let me know if you need to see more of my code or explain anything~!</p>