title: Why does this line of code produce an error?
body: <p>Look at the line: <code>while(node-&gt;next!= nullptr)</code>. This code gives me a bad alloc error.</p>
  
  <p>However, when it is changed to <code>while(node!= nullptr)</code>, it runs fine. Can someone explain why this error occurs?</p>
  
  <pre><code>void deleteNode(SNode &lt;Object&gt;* &amp; node, Object given)
  {
      SNode &lt;Object&gt;* temp= node;
      if(node-&gt;data== given)
      {
          node= node-&gt;next;
          delete temp;
          temp= nullptr;
      }
      while(temp-&gt;next!= nullptr) //this the problematic line
      {
          if(temp-&gt;next-&gt;data== given)
          {
              SNode&lt;Object&gt;* t= temp-&gt;next;
              temp-&gt;next= temp-&gt;next-&gt;next;
              delete t;
              t= nullptr;
          }
          temp= temp-&gt;next;
      }
  }
  </code></pre>