Well, there are different types of smart pointers. For instance:
You can create a scoped_ptr class that would be useful when distributing for a task in a block of code, and you want the resource to be automatically freed when the scope starts.
Sort of:
template <typename T> class scoped_ptr { public: scoped_ptr(T* p = 0) : mPtr(p) {} ~scoped_ptr() { delete mPtr; }
In addition, you can create shared_ptr , which acts the same but retains the number of links. When the number of links reaches 0, you will free.
shared_ptr will be useful for pointers stored in STL containers, etc.
So yes, you could use smart pointers for most of your program's purposes. But wisely think about which smart pointer you need and why.
Don't just โfind and replaceโ all the pointers you come across.
source share