![]() As a consequence the iterators returned from begin() and end() come from different vectors, hence the error message you're facing at runtime.Īlso, as pointed by Charles in his detailed answer, these temporary vectors will be destroyed by the time the function body of for_each is reached. Hope this will help you debug your problem.ĮDIT: it looks like I anticipated it right: after editing your question providing details, I can see you're definingĪs a consequence, in the following statement:įor_each(currState->getTiles().begin(),currState->getTiles().end(), drawTiles) Īs anticipated above, each call to getTiles() will return a separate temporary copy of the member vector. Indeed A->getV().begin() and A->getV().end() would be two iterators over different vectors: each A->getV() invocation returning a different copy of the private member. I'm only speculating but if A::getV() doesn't return a reference then it can explain the "Vector iterators are incompatible" error message. It constitutes of raw fish that is diced and. About Press Copyright Contact us Creators Advertise Developers Terms Privacy Policy & Safety How YouTube works Test new features Press Copyright Contact us Creators. If any of you has any good ideas about solving this you're welcome to help me ) In the mean time, I'll keep trying to fix it The Hawaiian version of Chirashi is called Poke (pronounced as Poh-kay) and it means to cut or slice in Hawaii. Tile *t = new tile(tp, (i+(SIDELENGTH/2))*SIDELENGTH, it seems that even through the vector is created and passes correctly, the tiles that were supposed to be in it aren't (they are lost after the : for (int j = 0 j < 8 j++) well for that problem, now it seems I have an issue with the creation of the tiles and stroing them in the row vector. ![]() And if you do spot any stupid stuff I might be doing, please let me know, I'm kind of new to C++ and the pointers and references still confuse me.ĮDIT2: Thanks guys, that worked perfectly. Is it easier to spot the problem now? I hope so. GetTiles in gameState.h: vector> getTiles() įor_each loops in main.cpp: for_each(currState->getTiles().begin(),currState->getTiles().end(), drawTiles) Īnd just in case it might be relevant: void gameState::setTiles(vector val) I don't know if it helps, but V is a private vector stored in class A, which has an accessor to it, and I'm trying to iterate through it in class B by doing: A->getV().begin(), A->getV().end(), etc.ĮDIT: Ok, so I think it is better to just post the code, and where problems might be arrising. I've looked on it and can't find any useful input on this. Now I'm getting a weird "Vector iterators incompatible" runtime error. simply does the same on the vector passed to it. I'm trying to use it in this way: for_each(V.begin(), V.end(), iterateThroughSmallVectors) It seems pretty neat but I'm having problems with it. iterate through the objects inside the individual vectorsĪnyway, I was just searching the web and I came accross the stl for_each function.create some of objects and store them in vectors, which get stored in another vector V.Hey there! I'm doing this project and right now I'm trying to:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |