Debugging:Working with boost::shared ptr
From SPCTools
(Difference between revisions)
Revision as of 17:14, 29 August 2006 Jtasman (Talk | contribs) ← Previous diff |
Current revision Jtasman (Talk | contribs) |
Current revision
The boost libraries (www.boost.org) 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.
Example:
#include <boost/shared_ptr.hpp> typedef boost::shared_ptr<MyObject> MyObjectPtr;
...
MyObjectPtr o(new MyObject());
In GDB:
>call (o.get())->print()