I got this working, but it didn’t make sense as a template parameter in SharedObjectPtr. Instead, I made a global class:
/** The DefaultDeletePolicy simply calls operator delete.
template <typename T>
static inline void destroy (T* t)
Then I went through all the JUCE containers and made them go through ContainerDeletePolicy<>::destroy. The only trick part was ReferenceCountedObject::decReferenceCount, since it doesn’t know the underlying type. So I changed it to this:
/** Decreases the object's reference count.
If doDelete is true the object will be deleted when the reference
count drops to zero. The delete is performed using the regular
operator and does NOT go through the ContainerDeletePolicy.
The return value indicates if the reference count dropped to zero,
so callers who know the derived type can use the ContainerDeletePolicy.
inline bool decReferenceCount (bool doDelete = true) noexcept
bassert (getReferenceCount() > 0);
if (--refCount == 0)
Then I made ReferenceCountedObjectPtr check the return value and call ContainerDeletePolicy<>::delete when the count drops to zero.