Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Automate Resource Management with shared_ptr

Your days of being frustrated by std::auto_ptr's limitations are over. The Library Extensions Technical Report 1 has added a new smart pointer class to the standard <memory> header. Find out how you can use shared_ptr to automate resource management and simplify common programming tasks.


advertisement
td::auto_ptr is the only smart pointer class available in C++98. Alas, since this class is neither assignable nor copy-constructible, creating containers of auto_ptr objects is illegal. This limitation has been a source of frustration and confusion for years. At last, the Library Extensions Technical Report 1 (TR1 for short) rectifies this embarrassment, adding a new smart pointer class called shared_ptr to the standard header <memory>. The following sections explain how to use shared_ptr to automate resource management. You will also learn how shared_ptr can simplify programming tasks that I've shown here before—such as simulating heterogeneous containers and implementing the Pimpl idiom.


How to combine smart pointers with STL containers and algorithms without risking undefined behavior?


Use the std::tr1::shared_ptr class.





Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap