If you want to keep the address of the member , a good way is to allocate memory for every member using "new". The vector just save the pointers to the address of these members. Don't forget to "delete " all members if you don't use this vector anymore.
An example:
[code]
//allocate
vector vec;
for(int i=0;i<3;i++) { int * a =new int; *a=i; vec.push_back(a); }
//deallocate
for(int i=0;i
delete vec[i];
}
[/code]
No comments:
Post a Comment