Understanding const_iterator with pointers?

I am trying to understand what const_iterator means. I have the following code example:

void CustomerService::RefreshCustomers()
{
    for(std::vector<Customer*>::const_iterator it = customers_.begin();
        it != customers_.end() ; it ++)
    {
        (*it)->Refresh();
    }
}

Refresh()is a method in a class Customer, and it is not defined as const. At first I thought that const_iterator was supposed to prohibit the modification of container elements. However, this code compiles without complaint. Is it because there is an additional level of indirection? What exactly does const_iterator mean?

UPDATE

And in this situation, is it best to use const_iterator?

+5
source share
3 answers

A const_iterator a vector<Customer*> Customer * const a Customer const*. , , (), , . , :

*it = ..something..;
+10

. - . , .

, , vector<const Customer*>.

+4

const_iterator , , , . , (, ...). - -const Refresh() , .

const_iterator [], , . , , , ,

list < pair < int , int > >

'it' const_iterator ,

it->first = 5

( const_iterator), .

+2

All Articles