开发者

Runtime Error : RunTime Error : map/set iterators incompatible

void Manager::Simulate(Military* military, Shalishut* shalishut,char* args[]){
    Simulation* simulation = Simulation::GetInstance();
    Time* time = Time::GetInstance();
    multimap<int,Task*>::const_iterator itTasks;
    itTasks = simulation->GetTasks().begin();
    while(itTasks != simulation->GetTasks().end()){
        while (itTasks->second->GetTimeStamp() == time->GetTime()){
            //TaskExecute(itTasks->second,military,shali开发者_如何学Goshut,args);
            itTasks++;
        }
        // Unit take car of vehicles
        time->TimeIncrease();
    }
}

in Debug is notice that the project falls when it comes to the first while.

thanks for help.


Does GetTasks() create a new map/set when it is called, and returns that? Or does it return a copy of a set where a reference would be appropriate?

If this is the case, then each call to GetTasks() returns a new object that is independent of previously returned objects. Comparing an iterator of one of these objects with an iterator of a different such object (like the begin() and end() iterators) doesn't make sense.

Make sure that all your iterators are coming from the same object and not from different copies of the same data.


Probably you want the GetTasks() function to return a reference, or a const reference, depending on constness of the Simulation object:

class Simulation {
   ...
   multimap<int,Task*>& GetTasks() { return m_tasks; } 
   const multimap<int,Task*>& GetTasks() const { return m_tasks; } 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜