c++ - Iterator skipping for loop -


i'm working list container i'm facing problem when use loop. don't understand why skipping, i'm printing "label" see until part working , 1 printing "first if " , skipping others. why problem happening?

header

class croute {     private:         vector<cwaypoint> m_pwaypoint;         vector<cpoi*> m_ppoi;         cpoidatabase* m_ppoidatabase;         list<cwaypoint*>m_proute;         cwpdatabase* m_pwpdatabase;      public:         void connecttopoidatabase(cpoidatabase* ppoidb);         void connecttowpdatabase(cwpdatabase* pwpdb);         void addpoiandwp(string namepoi, string afterwp);  }; 

cpp

void croute::addpoiandwp(string namepoi, string afterwp) {     cpoi* poi = m_ppoidatabase->getpointertopoi(namepoi);      list<cwaypoint*>::iterator pos1;      if( (m_pwpdatabase != 0) && (poi != 0))     {         cout << "first if " << endl; // printed          for(pos1 = m_proute.begin(); pos1 != m_proute.end(); pos1++) //here skipping         {             cout << "it's in loop" << endl;              if( (*pos1)->getname() == afterwp)             {                 cout << "waypoint found! " << endl;                 list<cwaypoint*>::iterator pos2 = pos1;                 m_proute.insert(++pos2,poi);             }              cout << "before leave loop" << endl;         }     }     else     {         cout << "wp not found / db not connected " << endl;     }         cout << "waypoint not found " << endl; // printed  } 

the issue empty list, .begin() , .end() return same value. i'd suggest insert either first value or null value before enter loop. try below.

    if(/*pos1 valid position*/) {           m_proute.insert(pos1);     }     for(pos1 = m_proute.begin(); pos1 != m_proute.end(); pos1++) //here skipping     {          cout << "it's in loop" << endl;         if( (*pos1)->getname() == afterwp)         {             cout << "waypoint found! " << endl;             list<cwaypoint*>::iterator pos2 = pos1;             m_proute.insert(++pos2,poi);         }          cout << "before leave loop" << endl;     } 

Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -