A great article from the CodeProject.com, about Boost smart pointers. It is mirrored here .
Sample Code based on Item 28 of Scott Myers book "More Effective C++". It works correctly, but I had to explicitly cast the smart pointers, to their parent types.
Code based on Item 10 in Scott Meyer's "Effective C++". This illustrates the use of a custom new operator in conjunction with the boost::shared_ptr.
Sample Code which illistrates the use of Boost shared pointers.
Sample Code which illistrates the use of Boost scoped pointers.
Sample Code which illistrates the use of Boost intrusive pointers.
Sample Code which generates resource losses. Valgrind catches the leak. The command line is:
valgrind --tool=memcheck --leak-check=full -v ./CyclicRef
The output is here .
Sample Code which illustrates how weak pointers can be used to solve cylic dependancies.
A thread on the difference between weak pointers, and raw pointers:
The boost documentation further explains the advantage of weak_ptr's over raw pointers. It says:
The weak_ptr class template stores a "weak reference" to an object that's already managed by a shared_ptr. To access the object, a weak_ptr can be converted to a shared_ptr using the shared_ptr constructor or the member function lock.