c++ - Iterator, loop causing seg fault! Why is it looping too much? -


the following code going through loop many times, , i'm baffled why. i've looked around , haven't seen case this. i'm new iterators there may simple here. thank help! , responses others in future.

std::multimap<std::string,std::vector<token> >::iterator end = thefacts.returncontents().end(); (mapiter = thefacts.returncontents().begin() ; mapiter != end; mapiter++) {    cout << "another iteration through facts" << endl;   cout << mapiter->first << endl;   cout << contents.begin()->first << endl;    if (mapiter->first == contents.begin()->first) {      cout << "same scheem type keep going!" << endl;      bool successfull = true;      cout << "starting seek match --> size --> " << mapiter->second.size() << endl;      (int x = 0; x< mapiter->second.size(); x++) {        std::cout << "processing! "                 << mapiter->second[x].gettokensvalue() << "<<<<<<is equal?>>>>>>"                 << contents.begin()->second[x].gettokensvalue() << std::endl;        if (mapiter->second[x].gettokensvalue()         == contents.begin()->second[x].gettokensvalue()) {          cout << "pushing value" << endl;         newbaby.push_back(contents.begin()->second[x]);        } else {          cout << "failure" << endl;         successfull = false;       }     }      if (successfull) {        std::cout << "match found" << std::endl;        if (returnme.contents.empty()) {          returnme = relation(contents.begin()->first, newbaby);         cout << returnme.tostring() << endl;        } else {          returnme.relationinsert(contents.begin()->first, newbaby);         cout << returnme.tostring() << endl;       }      } else {       // anser no     }   } } 

i know i'm not providing full code, can see form following output, size of map i'm iterating through 2, why looping third time!

where end --> size of maps (number of iterations shoudl occure2 iteration through facts snap snap same scheem type keep going! starting seek match --> size --> 4 processing! '12345'<<<<<<is equal?>>>>>>'67890' failure processing! 'snoopy'<<<<<<is equal?>>>>>>'van pelt' failure processing! '12 apple'<<<<<<is equal?>>>>>>'34 pear' failure processing! '555-1234'<<<<<<is equal?>>>>>>'555-5678' failure iteration through facts snap snap same scheem type keep going! starting seek match --> size --> 4 processing! '67890'<<<<<<is equal?>>>>>>'67890' pushing value processing! 'van pelt'<<<<<<is equal?>>>>>>'van pelt' pushing value processing! '34 pear'<<<<<<is equal?>>>>>>'34 pear' pushing value processing! '555-5678'<<<<<<is equal?>>>>>>'555-5678' pushing value match found print relation called  snap('67890','van pelt','34 pear','555-5678') iteration through facts segmentation fault (core dumped) 

here return contents does.

std::multimap<std::string,std::vector<token> > relation :: returncontents() {     return contents; } 

where contents private variable in relation class. doesn't seem me should cause error, unless there obvious don't know.

here return contents does.

there have error. function returncontents returns copy of map. call begin , end on 2 different copies it.

either return (const) reference:

const std::multimap<std::string,std::vector<token> >& relation::returncontents() {     return contents; } 

or create local copy:

std::multimap<std::string,std::vector<token> > tmp = thefacts.returncontents(); (mapiter = tmp.begin() ; mapiter != tmp.end(); mapiter++) { ... 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -