Sorry, debugger show the content of pvec right all the time; this is the complete code:
vector<int*>* pvec = new vector<int*>();
{
int ten=10, twenty=20, thirty=30;
int *pten = &ten;
//int* pten = new int(ten);
int* ptwenty = &twenty;
int* pthirty = &thirty;
pvec->push_back(pten);
pvec->push_back(ptwenty);
pvec->push_back(pthirty);
}
*(*pvec)[0] = 99; //no problems
int q = 1000;
(*pvec)[0] = &q;
vector<int*>::iterator it;
for(it=pvec->begin(); it != pvec->end(); ++it) {
cout << "*it " << *(*it) << " ";
}
//delete (*pvec)[0];
delete pvec;
vector<int*>* pvec = new vector<int*>();
{
int ten=10, twenty=20, thirty=30;
int *pten = &ten;
//int* pten = new int(ten);
int* ptwenty = &twenty;
int* pthirty = &thirty;
pvec->push_back(pten);
pvec->push_back(ptwenty);
pvec->push_back(pthirty);
}
*(*pvec)[0] = 99; //no problems
int q = 1000;
(*pvec)[0] = &q;
vector<int*>::iterator it;
for(it=pvec->begin(); it != pvec->end(); ++it) {
cout << "*it " << *(*it) << " ";
}
//delete (*pvec)[0];
delete pvec;
To copy to clipboard, switch view to plain text mode
Obviously ten will be destroyed out the scope but out of it (*pvec)[0] still contains the number 10 (and debugger show that this pointer doens't change....)
I'm sorry but could you explain me more? thanks
Bookmarks