Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

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.



Thanks for your registration, follow us on our social networks to keep up-to-date