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')
         x++;
    }
        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

This

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.