Deallocate vector of pointers

Here is the scenario:

I have a Mesh class that is abstract and then I have a Cube, Sphere, Cone, and Cylinder class that inherit from Mesh.

1
2
3
vector<Mesh*> m;

m.push_back(new Cube());


How do I deallocate the memory created by new?
1
2
3
4
5
while(!m.empty())
{
  delete m.back();
  m.pop_back();
}


Or... use a boost::ptr_vector instead, and it will do it automatically (but of course, then you need boost)
Thanks for the reply. When I implement the code, I get this error:

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)
Last edited on
I found the problem. I was trying to deallocate the memory twice. I did not check in the object destructors for NULL pointers.
Topic archived. No new replies allowed.