Home Forums C Programming Smart pointers… Reply To: Smart pointers…

#3111
will
Participant

Smart pointers are C++ objects that simulate simple pointers by implementing operator-> and the unary operator*. In addition to sporting pointer syntax and semantics, smart pointers often perform useful tasks—such as memory management or locking—under the covers, thus freeing the application from carefully managing the lifetime of pointed-to objects.

The simplest example of a smart pointer is auto_ptr, which is included in the standard C++ library. You can find it in the header , or take a look at Scott Meyers’ auto_ptr implementation. Here is part of auto_ptr’s implementation, to illustrate what it does:

You can find many readings on smart pointers. I have found two very interesting readings on smart pointers.

http://ootips.org/yonat/4dev/smart-pointers.html
http://www.informit.com/articles/article.asp?p=31529