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?
Refresh()
Customer
UPDATE
And in this situation, is it best to use const_iterator?
A const_iterator a vector<Customer*> Customer * const a Customer const*. , , (), , . , :
const_iterator
vector<Customer*>
Customer * const
Customer const*
*it = ..something..;
. - . , .
, , vector<const Customer*>.
vector<const Customer*>
const_iterator , , , . , (, ...). - -const Refresh() , .
const_iterator [], , . , , , ,
list < pair < int , int > >
'it' const_iterator ,
it->first = 5
( const_iterator), .