c++ - Iterator on vector error for operands "=" and "!=" -


using namespace std;     vector<idrawable*>::const_iterator itdrawable;     for(itdrawable= scene.getdrawables().begin(); itdrawable!=scene.getdrawables().end();itdrawable++){         idrawable *drawable =(*itdrawable);         drawable->draw();     } 

this code passing me error:

description resource path location type no match 'operator!=' (operand types 'std::vector<idrawable*>::const_iterator {aka __gnu_cxx::__normal_iterator<idrawable* const*, std::vector<idrawable*> >}' , 'std::vector<const idrawable*>::const_iterator {aka __gnu_cxx::__normal_iterator<const idrawable* const*, std::vector<const idrawable*> >}')

and

description resource path location type no match 'operator=' (operand types 'std::vector<idrawable*>::const_iterator {aka __gnu_cxx::__normal_iterator<idrawable* const*, std::vector<idrawable*> >}' , 'std::vector<const idrawable*>::const_iterator {aka __gnu_cxx::__normal_iterator<const idrawable* const*, std::vector<const idrawable*> >}')

i have looked these , should have const_iterator ? yet scene.getdrawables() looks like:

const std::vector<const idrawable*>& getdrawables() const {         return drawables;     } 

so iterator should const_iterator right ? have no clue has change...

your

const std::vector<const idrawable*>& getdrawables() const 

returns const reference vector of const idrawable* pointers.

vector<idrawable*>::const_iterator itdrawable;  

declares const_iterator vector of different type (idrawable*, not const idrawable*). either change definition vector<const idrawable*>::const_iterator itdrawable; or use auto declare iterator in for loop,

for(auto itdrawable= scene.getdrawables().cbegin(); ...) 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -