Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm going to take a wild guess and say that the <code>Simulation::GetTasks()</code> signature looks like this:</p> <pre><code>multimap&lt;int,Task*&gt; GetTasks() const; </code></pre> <p>This creates a new multimap (a <em>copy</em>) each time you call it.</p> <p>When comparing iterators, both of the <code>multimap&lt;int,Task*&gt;</code> iterators must come from the same container; since you're getting a new copy each time you call <code>GetTasks()</code>, you violate this constraint, and this is the source of your error. You also have another problem - the temporary multimap copies are destroyed after the statement they're created in, so your iterators are invalidated instantly.</p> <p>You have two choices; one is to capture a copy locally and use that copy consistently:</p> <pre><code>multimap&lt;int,Task*&gt; tasks = simulation-&gt;GetTasks(); multimap&lt;int,Task*&gt;::iterator itTasks; itTasks = tasks.begin(); while(itTasks != tasks.end()){ while (itTasks-&gt;second-&gt;GetTimeStamp() == time-&gt;GetTime()){ TaskExecute(itTasks-&gt;second,military,shalishut,args); itTasks++; } // Unit take car of vehicles time-&gt;TimeIncrease(); } </code></pre> <p>Another is to have <code>GetTasks()</code> return a reference to a <em>persistent</em> multimap, ensuring the same one is used each time:</p> <pre><code>multimap&lt;int,Task*&gt; &amp;GetTasks(); </code></pre> <p>Or a const reference:</p> <pre><code>const multimap&lt;int,Task*&gt; &amp;GetTasks() const; </code></pre> <p>This has the advantage of avoiding the (potentially large) overhead of copying the <code>multimap</code>.</p> <p>Note that using a const reference requires using <code>const_iterator</code>s to step through the multimap. I would recommend defining both const and non-const accessors (C++ will pick the right one based on if the <code>Simulation</code> pointer or reference is const), unless you want to disallow direct modification of the underlying <code>multimap</code> entirely, in which case you can define only the <code>const</code> variant.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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