Debugging:Working with boost::shared ptr

From SPCTools

Jump to: navigation, search

The boost libraries ( provide very useful C++ libraries. They offer a nice implementation of templated shared (reference counting) pointers. This allows for easier garbage collection: destructors are automatically called when the last shared_ptr to this object lets go of it. These are wrapper objects which override the dereference operator. GDB isn't smart enough to understand this when stepping through code. So, use the get() method of the shared_ptr to return a pointer to the stored object.


#include <boost/shared_ptr.hpp>
typedef boost::shared_ptr<MyObject> MyObjectPtr;

MyObjectPtr o(new MyObject());


>call (o.get())->print()
Personal tools