Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As I understand you're checking your pointer against NULL for the "remaining" items that might have not been deleted yet. But for the items you delete before your cleanup stage, do you set the pointer to NULL?</p> <p>Notice that when you delete an object the pointer is <strong>not</strong> automatically set to NULL. So if you're not doing that you're trying to delete the same object twice (because your if statement will always be true), what could cause an access violation.</p> <p>The code below is an example that causes a double deletion. It can be fixed if you uncomment the line that sets the pointer to NULL.</p> <pre><code> #include &lt;cstddef> struct Item {}; int main() { Item * p = new Item(); delete p; //If you don't make the pointer null... //p = NULL; if (p != NULL) //You delete the object twice. delete p; } </code></pre> <p><strong>EDIT:</strong> I see you're getting the error exactly on the <strong>for</strong> line. So I'm wondering... </p> <p>Apparently you have a <em>MyClass</em> that contains a <em>_transactions</em> member, which is a hash table with <em>MyClass</em> pointers as the data type. If the clean up code is performed inside a member function of <em>MyClass</em>, is it possible that you're deleting (for some reason) the <em>MyClass</em> instance that owns the <em>_transactions</em> you're iterating?</p> <p>In this case you could get an error at <em>it++</em> statement inside the <em>for</em> since the <em>this</em> object no longer exists. (Naturally, the error could be somewhere else too, like on the delete itself.)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload