Creating QSharedPointer <void>
For historical reasons, I use QSharedPointer<T> in my software. In some cases, we want to save boost::shared_ptr<T> , which point to the same data, and which should support QSharedPointer<T> instances.
The general way to do this is to keep a copy of another smart pointer in the removal of boost::shared_ptr<T> . But in order to prevent the deleter from being of different types for different T s, which would make it easy to get QSharedPointer back using boost::get_deleter , when the corresponding boost::shared_ptr was upcast, I wanted to save the original QSharedPointer<T> as QSharedPointer<void> inside the deleter , unlike using T
But I found that QSharedPointer not up to the task, because it throws errors, for example, "a link to void cannot be executed" when compiling my header.
Does anyone have an idea on how to make this work without subjecting T removal?
You cannot define QSharedPointer because void is not the correct type. You can define QSharedPointer and then apply to T * and char * and as follows:
class A {}; QSharedPointer<char> x((char *)new A); A *ptr = (A *)x.data(); Ugly, but it works. You may also need to pass to Deleter, which correctly removes the class for the constructor, so that your class is destroyed correctly.
A better alternative would be to use a base class.