This question already has an answer here:
- protected destructor with unique_ptr 2 answers
I want to bind with the class from third party library. The class have some pure virtual functions but the destructor is protected and virtual.
In order to bind the class, I have to write a derived class that overrides the pure virtual functions (https://pybind11.readthedocs.io/en/stable/advanced/classes.html)
so the code is like this
class Parent {
public:
virtual void foo() = 0;
protected:
virtual ~ Parent() //Dtor
{
}
};
class PyParent : public Parent
{
public:
void foo () override {
PYBIND11_OVERLOAD_PURE(
void,
Parent,
foo
);
}
};
void init(py::module & m) {
py::class_<Parent, PyParent> p(m, "p");
}
However, since the destructor of the base class is declared as protected, the following errors are thrown
error: ‘virtual Parent::~Parent()’ is protected
virtual ~ Parent() //Dtor
I can not modify the base class since it's a third party library.
Any idea to bind the class with pybind11?