c++ - Vector iterator not incremental -


i'm trying implement simple menu application in qt , got point have make filter button. qt giving error , don't know how interpret it. come these 2 functions. i'll post photo of error well. code filter operation:

vector<car> controller::filterbycategory(string category) {     vector<car> fin;     vector<car> all(repo->getall());      copy_if(all.begin(), all.end(),fin.begin(),                 [&](car& cc) { return (cc.getcategory()==category); });     return fin; } 

qt function calling filter function:

void ownerwindow::filtercategory() {     qstring scategory = lcategory->text();     string category = scategory.tostdstring();     vector<car> cars = ctrl->getallcars();     vector<car> fin;     try {         fin = ctrl->filterbycategory(category);     }     catch(warehouseexception& ex) {             qmessagebox::information(this, "error!", qstring::fromstdstring(ex.getmsg()));     }     catch(...) {         qmessagebox::information(this,"wtf",qstring::fromstdstring("huuuuuh"));     } 

here program crashes following error: enter image description here

any idea happening, why qt won't catch error or why code not working?

edit: tried count number of elements add can create final vector fixed size. didn't work.

vector<car> controller::filterbycategory(string category) { //    vector<car> fin;     vector<car> all(repo->getall());     int = 0;     for_each(all.begin(),all.end(), [=](const car& cc) mutable {         if (cc.getcategory() == category) {             i++;         }     });     vector<car> fin(i);     copy_if(all.begin(), all.end(),fin.begin(),                 [&](car& cc) { return (cc.getcategory()==category); });     return fin; } 

the problem filterbycategory vector fin empty, either need create correct number of elements, or use std::back_inserter create elements on demand.

by way, there's no need copy all vector first. use e.g. repo->getall().begin() directly in std::copy_if call.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -