hello there
i'm having a list iterator not incrementable problem
i have a adjacency matrix "adj(2d vectors)" + i have a char vector in name color and i have a int glist
i'm having a problem with the following function

for(list<int>::iterator it = glist.begin(); it != glist.end(); it++)
        int x =0;
    for(int i=0;i<adj.at(*it).size();i++){
        if(color.at(adj.at(*it).at(i)) == 'w')
        if(x == 0)
            it = glist.erase(it);

what i want from this function is to test if the neghbors of each elemnt in glist hase neighbors with white color (i.e the color of the neighbor in the color vector == "w" if it doesn't then deltet the element from the glist
but when i compile an error of list iterator not incrementable shows up
any help will be appreciated

Edited by pritaeas: Moved to cpp.

2 Years
Discussion Span
Last Post by Moschops


it = glist.erase(it);

moves the iterator to the next element, so if you do this, you should not increment the iterator again at the end of the loop. Move the it++ out of the for loop header and do it yourself only if x did not == 0.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.