2016-04-23 56 views
0

我試圖遍歷對的載體,我需要通過這樣做是爲了增加對中的一個元素。增量值

for (std::vector<std::pair<Process *, int> >::const_iterator it = process.begin(); it != process.end(); it++) { 
     if (queue.size() == 0) 
      break;                                             
     while (queue.size() > 0 && it->second < threadsPerProcess * 2) { 
      it->first->send(queue.front()); 
      queue.pop_front(); 
      ++it->second; // value i am trying to increment 
     } 
} 

可能有人告訴我,我在做什麼錯誤?

回答

1

更改此:

for (std::vector<std::pair<Process *, int> >::const_iterator it = process.begin(); it != process.end(); it++) { 

這樣:

for (std::vector<std::pair<Process *, int> >::iterator it = process.begin(); it != process.end(); it++) { 

,讓你真正修改你迭代的元素。

0

如果您修改內容,請不要使用const_iterator,請使用簡單的iterator