Home › Forums › C Programming › Smart pointers… › Reply To: Smart pointers…
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
1 2 3 4 5 6 7 8 9 10 11 | template <class T> class auto_ptr<br /> {<br /> T* ptr;<br /> public:<br /> explicit auto_ptr(T* p = 0) : ptr(p) {}<br /> ~auto_ptr() & nbsp; & nbsp; {delete ptr;}<br /> T& operator*() & nbsp; {return *ptr;}<br /> T* operator->() &nb sp; {return ptr;}<br /> // ...<br /> };<br /> </class> |
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