Is this a memory leak? vectors

1
2
3
4
5
std::vector<Pie> PtrPie;
Pie* ptr1 = new Pie;
PtrPie.push_back(ptr1);
delete *(PtrPie.begin() + index); // deletes Pie, index is the position of the ptr, this would be 0 in this example
PtrPie.erase(PtrPie.begin() + index); // and this removes the ptr from the vector 


imagine Pie and index are defined somewhere.

I'm I doing it right? deleting (what I think is) Pie by dereferencing the iterator to the pointer in the vector, and then removing the pointer from the vector.
Last edited on
It looks right.

Note that
delete *(PtrPie.begin() + index);
could be written as
delete PtrPie[index];
Last edited on
thanks, I've been using lists for too long, completely forgot I could do that with vectors.
Topic archived. No new replies allowed.