Here is only a short introduction of the article, if you are interested, please goto the author’s website for the full text.

Most people have heard of the standard auto_ptr smart pointer facility, but not everyone uses it daily. That’s a shame, because it turns out that auto_ptr neatly solves common C++ design and coding problems, and using it well can lead to more robust code. This article shows how to use auto_ptr correctly to make your code safer–and how to avoid the dangerous but common abuses of auto_ptr that create intermittent and hard-to-diagnose bugs.

Why Call It an "Auto" Pointer?

auto_ptr is just one of a wide array of possible smart pointers. Many commercial libraries provide more sophisticated kinds of smart pointers that can do wild and wonderful things, from managing reference counts to providing advanced proxy services. Think of the Standard C++ auto_ptr as the Ford Escort of smart pointers: A simple general-purpose smart pointer that doesn’t have all the gizmos and luxuries of special-purpose or high-performance smart pointers, but that does many common things well and is perfectly suitable for regular daily use.

What auto_ptr does is own a dynamically allocated object and perform automatic cleanup when the object is no longer needed. Here’s a simple example of code that’s unsafe without auto_ptr:

Visit the author’s website for more details.