Jon Jon - 1 year ago 69
C++ Question

intrusive_ptr: Why isn't a common base class provided?

to be defined. Why isn't a base class provided which will do this? There is an example here:, but the poster says "I don't necessarily think this is a good idea". Why not?

Update: I don't think the fact that this class could be misused with Multiple Inheritance is reason enough. Any class which derives from multiple base classes with their own reference count would have the same issue. Whether these refcounts are implemented via a base class or not makes no difference.

I don't think there's any issue with multithreading;
offers atomic reference counting and this class could too.

Answer Source

Boost provides a facility for that. It can be configured for either thread-safe or thread-unsafe refcounting:

#include <boost/intrusive_ptr.hpp>
#include <boost/smart_ptr/intrusive_ref_counter.hpp>

class CMyClass
    : public boost::intrusive_ref_counter<

boost::intrusive_ptr<CMyClass> myPtr;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download