
Stefan Slapeta wrote:
class intrusive_ptr_base { friend void intrusive_ptr_add_ref(intrusive_ptr_base*); friend void intrusive_ptr_release(intrusive_ptr_base*);
int ref_count__;
protected: intrusive_ptr_base() : ref_count__(0) {}
virtual ~intrusive_ptr_base() {}
I don't necessarily think this is a good idea, but I will only comment on the code. You can use CRTP here instead, to avoid the virtual destructor. Something like: template<class Derived> class intrusive_ptr_base { friend void intrusive_ptr_add_ref(intrusive_ptr_base* o) { ++o->ref_count__; } friend void intrusive_ptr_release(intrusive_ptr_base* o) { if (--o->ref_count__ == 0) { delete static_cast<Derived*>(o); } } int ref_count__; protected: intrusive_ptr_base() : ref_count__(0) {} }; -- Daniel Wallin