H
Hunter Hou
Hi,
I just ran into one simple but confusing problem. Here is my code skeleton:
int main()
{
vector<int> vecInt( 5 );
typedef vector<int>::interator VI
for( VI p = vecInt.begin(); p != vecInt.end(); p++ ) {
.......
}
sort( .... );
// print sorted vector elements
for( p = vecInt.begin(); p != vecInt.end(); p++ ) {
.......
}
.......
return 0;
}
The compiler complains that:
sort.cpp: In function `int main()':
sort.cpp:62: name lookup of `p' changed for new ISO `for' scoping
sort.cpp:53: using obsolete binding at `p'
It's very confusing here sine I re-initialize p by begin(). who knows the
reson of this? what is the most elegant way of using 'p' here?(don't tell me
using [] operator instead )
Thanks,
Hunter
===
P.S:I solved this error by re-define p as exactly same as the first "for"
loop, which I don't like.
I just ran into one simple but confusing problem. Here is my code skeleton:
int main()
{
vector<int> vecInt( 5 );
typedef vector<int>::interator VI
for( VI p = vecInt.begin(); p != vecInt.end(); p++ ) {
.......
}
sort( .... );
// print sorted vector elements
for( p = vecInt.begin(); p != vecInt.end(); p++ ) {
.......
}
.......
return 0;
}
The compiler complains that:
sort.cpp: In function `int main()':
sort.cpp:62: name lookup of `p' changed for new ISO `for' scoping
sort.cpp:53: using obsolete binding at `p'
It's very confusing here sine I re-initialize p by begin(). who knows the
reson of this? what is the most elegant way of using 'p' here?(don't tell me
using [] operator instead )
Thanks,
Hunter
===
P.S:I solved this error by re-define p as exactly same as the first "for"
loop, which I don't like.