A vector( or queue) of pointers

Hi,

If I have a vector( or a queue) I was wondering what would happen when I pop an element from it. The pointers are assigned to dynamically allocated memory locations. If I pop them , do they call the destructor function of the objects pointed to by the pointer, or is that allocated memory just lost??
Also when I pop an element, Do i get the value or do i get a reference to the object popped.

Please let me know if my question is not clear, I shall provide more details

Thanks,
Mahesh
If I have a vector( or a queue) I was wondering what would happen when I pop an element from it.

You can read about this here:
http://www.cplusplus.com/reference/stl/vector/pop_back/
http://www.cplusplus.com/reference/stl/queue/pop/

The pointers are assigned to dynamically allocated memory locations.

What pointers?

If I pop them , do they call the destructor function of the objects pointed to by the pointer, or is that allocated memory just lost??

Still don't know what pointers you are talking about. The popped object destructor will be called for sure. The allocated memory won't lost, it's managed by the underlying container, you don't have to worry about that.

Also when I pop an element, Do i get the value or do i get a reference to the object popped.

As you can see from the links above, both of these return nothing (void).
@R0mai
The OP said A vector( or queue) of pointers so I assume the pointers are the elements of the containers

@maheshravishankar
If you are not using something like smart pointers, the memory won't be freed
@R0mai
Yeah , as Bazzy said, pointers are elements of my container.

So, for example,
if I have

vector<my_class*> temp;
my_class *temp2 = temp.pop_back();


where "my_class" is a class I have defined, then temp2 should point to an instance of the class right?
No. pop_back() does not return anything. It simply removes the last element.
Topic archived. No new replies allowed.