what is smart piointer?
NOTE : [I][This question was asked by lavanya] [/I]
Printable View
what is smart piointer?
NOTE : [I][This question was asked by lavanya] [/I]
Smart pointers are objects which store pointers to dynamically allocated (heap) objects. They behave much like built-in C++ pointers except that they automatically delete the object pointed to at the appropriate time. Smart pointers are particularly useful in the face of exceptions as they ensure proper destruction of dynamically allocated objects. They can also be used to keep track of dynamically allocated objects shared by multiple owners.
Conceptually, smart pointers are seen as owning the object pointed to, and thus responsible for deletion of the object when it is no longer needed.
*Smart pointers is a structure in c++ and it is similar to pointers in c with some additional features like it throws an exception when it's NULL and someone tries to dereference it, or it destroys its contents automatically when it goes out of scope.
*We use smart pointers in order to increase a pointer's IQ.
*They keep track of the objects they point to for the purpose of memory management.
*They prevent memory leaks by making the resource deallocation automatic: when the pointer to an object is destroyed, the pointed object is destroyed too.
*They are implemented as a template class by means of operator overloading.