Trampoline usage with interface class #600
-
Hi, I'm running into an issue when trying to bind an interface class (pure virtuals) that has a protected destructor. class IPureVirtualInterface
{
public:
virtual void Set(bool value) = 0;
protected:
virtual ~IPureVirtualInterface() = default;
};
class PyPureVirtualInterface : public IPureVirtualInterface
{
public:
NB_TRAMPOLINE(IPureVirtualInterface, 1);
void Set(bool Value) override { NB_OVERRIDE_PURE(Set, Value); }
};
NB_MODULE(_core, m)
{
m.def("test_param", [](IPureVirtualInterface& i) {
i.Set(true);
});
nb::class_<IPureVirtualInterface, PyPureVirtualInterface>(m, "IPureVirtualInterface")
.def(nb::init<>())
.def("Set", &IPureVirtualInterface::Set, "Set a value");
} import package_name._core as m
class CustomPureVirtualInterface(m.IPureVirtualInterface):
def Set(self, arg: bool) -> None:
print(f"PY: Set called with value: {arg}")
def test_interface():
x = CustomPureVirtualInterface()
m.test_param(x) I've tried adding a destructor to If this is not possible to achieve, it is acceptable to forego the trampoline, since it is a nice to have in my usecase. But then my followup will be how to bind that interface class, since I could not find any details on Non-public destructors like mentioned in pybind11 https://pybind11.readthedocs.io/en/stable/advanced/classes.html#non-public-destructors |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You need to un-protect the destructor of the parent class. The type of code you are trying to bind is not supported by nanobind. |
Beta Was this translation helpful? Give feedback.
You need to un-protect the destructor of the parent class. The type of code you are trying to bind is not supported by nanobind.