const and iterators


helllo, i've got a problem with the code below. I think the problem lies with the const command . I understand you have to use const_iterator with variables that are passed as const. However in the code i->printSummary() it reports a problem? I've been reading about the const command and has to be used with some care. Is there anything wrong with the function?. The prototype has identical parameter listing.

ironically, i have had this piece of code working fine (with some help) when it was slightly more complicated, and i used a pointer to mutant type and had the following (*i)->printSummary() !!.



void eligableParents( const list < mutantType> &tempList)
{
std::list < mutantType> :: const_iterator i;

for ( i = tempList.begin();
i != tempList.end();
++ i )
i->printSummary();



}
mutantType::printSummary must be declared to be const to be called from const object ( or iterators )
right....

do you mean like this in the prototype..?


mutantType::printSummary() const;

yes
Topic archived. No new replies allowed.