c++ - Do I need to write the `const` keyword when passing a `const_iterator` as argument? -


static void myclassmethod(           std::list<aclass>                 & anobject,     const std::list<aclass>::const_iterator & beginningpoint); 

in code, i'm passing const_iterator of const stl object. feels 1 of constantnesses redundant.

how differ if remove const keyword, or if change const_iterator iterator?

std::list<aclass>::iterator& 

you can change value through iterator , can change iterator points outside function.

std::list<aclass>::const_iterator& 

you can't change value through iterator can change iterator points outside function.

const std::list<aclass>::iterator& 

you can change value through iterator can't change iterator points outside function.

const std::list<aclass>::const_iterator& 

you can't change value through iterator , can't change iterator points outside function.

take note iterators passed reference. if passed value, first const wouldn't matter much. because changing position of iterator effect local copy.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -