I am facing problems to convert the unique pointer unique_ptr<Derived,Deleter<Derived>>
to the unique pointer unique_ptr<Base,Deleter<Base>>
. The class Derived
is, of course, derived from the class Base
, and the template class Deleter
overloads the ()
operator to create a custom deletion routine to the unique pointer. Using std::move
returns an error and all my other attemps have failed. Is this conversion really possible?.
class Base
{
};
class Derived : public Base
{
};
template <typename T> class Deleter
{
public:
void operator()(T* pointer)
{
//custom deletion
}
};
int main()
{
std::unique_ptr<Derived,Deleter<Derived>> derived_pointer(new Derived(), Deleter<Derived>());
std::unique_ptr<Base,Deleter<Base>> base_pointer=std::move(derived_pointer);//error, conversion not possible
return 0;
}