How to delete pointer memory of std::deque or something

Hi. I am creating MFC Program in Visual Stduio 2010.

I want to use std::deque and input Parent Class Pointer in container.
so, I declared variable as follows

1
2
3
4
5
  //A.h
  queue<CMyParent*> m_qMemories;

  //A.cpp
  m_qMemories.push_back(new CMyChild(Parameters..));


I want to manage CMyChild Objects as only deque.

But I don't know how to delete Object Memory of CMyChild type.

Please let me know if you can.

Thank you.
Last edited on
Get the pointer from the queue. Call delete on it.

Repeater’s already given you the proper answer to your question (“how to delete Object Memory of CMyChild type”), but you could also wonder whether you need pointers or not («How could I get rid of my raw pointers?»).

Firstly, you should consider standard containers already take care of ‘keeping alive’ or destroying the objects you push into them, so there could be no need to explicitly allocate those in the heap, since they will live until the container lives.

Secondly, you could replace raw pointers with smart pointers.
Topic archived. No new replies allowed.