title: C++ | List iterator not incrementable
body: <p>I am trying to iterate through a list and then, if the object's plate number matches the one given through the parameters, and if the toll (calculated in toll()) is less than or equal to the given cents, remove/erase the object from the list. I keep getting the error that the list iterator cannot be incremented and I'm clueless as to how to fix it.</p>
  
  <pre><code>void one_time_payment(string&amp; plate_number, int cents) {
      // TODO: REWRITE THIS FUNCTION
      std::list&lt;LicenseTrip&gt;:: iterator it;
      for (it = listLicense.begin(); it != listLicense.end(); std::advance(it, 1)) {
          if (it-&gt;plate_number().compare(plate_number) == 0) {
              cout &lt;&lt; "Matching Plate Found" &lt;&lt; endl;
              if (it-&gt;toll() &lt;= cents) {
                  cout &lt;&lt; "Can be paid" &lt;&lt; endl;
                  it = listLicense.erase(it); //Error: list iterator cannot be incremented
              }   
          }
      }
      cout &lt;&lt; "End of Iterator" &lt;&lt; endl;
  }
  </code></pre>