Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
A smart pointer is a container that manages a pointer. Prefer to use smart pointers over normal pointers [1-3].
Boost.Smart_ptr is the Boost smart pointer library.

boost::scoped_ptr
boost::shared_ptr
boost::weak_ptr
QPointer
std::auto_ptr
std::shared_ptr
std::tr1::shared_ptr
std::unique_ptr
Smart pointers and null
Boost smart pointers check for null themselves, so there is no need to check these to be inititialized. In the example below a member variable of a class is requested from an unitialized smart pointer. The program will abort and the runtime error will be shown.
#include <boost/scoped_ptr.hpp> |
The code below shows that initializing a boost::shared_ptr with null will not be easy, but even when it succeeds, boost::shared_ptr will check itself for null. A boost::scoped_ptr can be null, but will check itself for it as well.
#include <boost/scoped_ptr.hpp> |
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.