Smart Pointer Alternative To shared_ptr

shared_ptr brings convenience to memory management but it also comes at a cost.  It blocks the use of covariant return types.  Also it makes interfacing with other environments difficult, for instance if you wanted to make a C wrapper around your C++ code.  shared_ptr keeps an internal reference count of the object, but if we switch that around and put the reference count inside of the object we could choose when to use smart pointers without losing a consistent count.  That way we can keep our interfaces clean of smart pointers, but use them internally to get their benefit.  Without further ado I present refcountptr with the disclaimer that I wrote it for this post, I’ve only done minimal testing.


 example of usage:


Leave a Reply

Your email address will not be published. Required fields are marked *