Friday, June 3, 2011

Automatic destruction of dynamic object

Use unique_ptr<> template object for that.
Ex
{
       unique_ptr<T> p = new T();
}
Dynamic object that is referred by p is destroyed when control thread exits the block.
This is achieved by coupling automatic variable p with the dynamic object. It is ensured by unique_ptr 

Excellent  article on www.stackoverflow.com by Matthieu M.

No comments:

Post a Comment