I am trying to call APIs from a third party library.
There is a trouble when I want to use unique_ptr with a class having protected destructor.
Here is the e
Unfortunately, the real way to get rid of this issue is to not derive classes from Parent, and to not manage the lifetime of Parent objects (or any derived classes) using std::unique_ptr.
In other words, you need to redesign your classes.
The reasons I say this are
Parent a protected non-virtual destructor, the intent is most likely to avoid having a Parent * which actually points at an instance of a derived class and is released using operator delete. A library designer will not (normally) do this without good reason.std::default_delete a friend of Parent). However, std::default_delete is used by unique_ptr to release the managed object. And it uses operator delete. That gives undefined behaviour if the object being managed by the unique_ptr is of a type derived from Parent.So, in short, you're working around the intent of (whoever designed) your third party library and, if you force the code to compile anyway, your reward will be undefined behaviour.