如果你传递过来一个const类型的容器,那么只能用const_iterator来遍历。
C++ Code
1
2 3 4 5 |
void Method(const vector<int> vInt)
{ vector<int>::const_iterator iter; // ... } |
简单示例
const iterator几乎没什么用途
C++ Code
1
2 3 4 5 6 7 |
vector<int> ivec;
vector<int>::const_iterator citer1 = ivec.begin(); // const int *p; ( *p is const) const vector<int>::iterator citer2 = ivec.begin(); // int* const p; ( p is const) ; //error ; //right ++citer1; //right ++citer2; //error |