On Mon, 25 Jan 1999, Burak Serdar wrote:

> After a vector insert operation, all iterators (pointers) which are pointing
> to vector elements are invalid. This is how STL vector semantics are defined.
> It is not a replacement for arrays. But of course, if you store references to
> objects in a vector and keep the pointers to objects instead of pointers into
> a vector, you will not loose anything.
> 

It is not true, I used code below to test it:

#include <iostream.h> 
#include <stl.h> 

int main(){
        vector<long> v;
        vector<long>::iterator it;

        long i=0;
        for(i=0;i<10;i++)v.push_back(i);
        vector<long>::reference r=v[0];
        cout<<r<<"\n";
        for(i=10;i<100;i++)v.push_back(i);
        cout<<r<<"\n";
        
        return 0;
}


This is the result:
 
0 
268678424

The reference 'r' can not trace v[0].

Sincerely Yours,

FengLou Mao
*******************************
ADD:Mr. FengLou Mao
    Peking University
    BeiJing
    P.R.China
Tel:86-10-62751490
Fax:86-10-62751725

Reply via email to