Boost logo

Boost Users :

From: bringiton bringiton (kneeride_at_[hidden])
Date: 2006-07-10 01:58:19


This question is based on curiosity. How does std::vector::pop_back() call
the destructor of the item getting removed?

i understood std::vector to be a contigious array of memory, therefore an
item's memory does not go out of scope when being popped. ie the item goes
out of scope when the entire array goes out of scope.

example code: the reference count is decremented when the item is popped
from the vector.

boost::shared_ptr<int> item1(new int(1));

std::vector< boost::shared_ptr<int> > vect1;
vect1.push_back(item1);

std::cout << item1.use_count() << std::endl;
vect1.pop_back();
std::cout << item1.use_count() << std::endl;



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net