Browse - Programming Tips - Which "smart pointer" should I use?

Date: 2008may6
Language: C++

Q.  Which "smart pointer" should I use?

A.  I prefer STL's auto_ptr

Example use:

#include <memory> class Thing { int a; int b; }; main() { std::auto_ptr<Thing> a(new Thing); std::auto_ptr<Thing> b; b = a; // Now b owns the Thing } // a and b are delete-ed when they go out of scope (here)
Using automatic (ie stack) variables is even better.