|
Boost Users : |
From: Manuel Jung (gzahl_at_[hidden])
Date: 2007-05-08 02:52:28
> If I have an attribute of a vector of boost shared_ptr in a class, like
> this:
>
> class A;
>
> class B {
> public :
> ~B() { ...}
> private:
> std::vector< boost::shared_ptr<A> > aVector;
>
>
> };
>
> What do I need to do in the destructor of B so that all the memory
> used by a vector of shared_ptr of A ('aVector') will be freed
> correctly?
You dont need to do anything in there. If a instance of class B is
destroyed, the Vector B::aVector will be destroyed automaticly. If the
shared_ptr<A>s are the last shared_ptr<>s to this particular Instance of A,
A will also be destroyed.
Even if the memory will be freed automaticly, you have to allocate it in the
begining, like: aVector.push_back(new A());
Kind Regards,
Manuel Jung
> Thank you.
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