
Originally Posted by
wysota
Well... those are the methods of your vector class. With Qt you could do:
qDeleteAll(*pvec);
qDeleteAll(*pvec);
To copy to clipboard, switch view to plain text mode
BTW. What is the rationale of storing pointers to ints in a vector?
It's just one prove.
I guess you allude to the fact that it's the same write int ten=10; vec.push_back(ten); or better vec.push_back(10) and I haven't any advantage to have pointer to primitive types (and in this way I write less and clear code).???
However: could you explain me what happen on stack/heap? I mean: pvec point to a block on the heap with "new"; pten with "new" point to a block (that contains an int) on the heap too; ptewnty and pthirty point on the stack; so on the heap I have pvec that contain 3 point to int: one of these, points to a block on the heap (10); the others two, point to a block on the stack..Is this?
Again:
if I have:
vector<int*>* pvec = new vector<int*> ();
{
int ten = 10;
int* pten = &ten;
pvec.push_back(pten);
}
//here the pointers of pvec are still OK
vector<int*>* pvec = new vector<int*> ();
{
int ten = 10;
int* pten = &ten;
pvec.push_back(pten);
}
//here the pointers of pvec are still OK
To copy to clipboard, switch view to plain text mode
Out the scope pten was undefined but inside pvec there is still a valid pointer becasuse the push_back make a copy of pointer?Is this?
Thanks
Bookmarks