pybind11
pybind11 copied to clipboard
[BUG]: Pure virtual method overriding using mixin class gives: Tried to call pure virtual function …
Required prerequisites
- [X] Make sure you've read the documentation. Your issue may be addressed there.
- [X] Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- [x] Consider asking first in the Gitter chat room or in a Discussion.
What version (or hash if on master) of pybind11 are you using?
2.13.5
Problem description
I cant override pure virtual functions using mixin classes. Pybind does not realize that the function in question does exist but is provided by the mixin class.
Reproducible example code
struct M {
int f() { return 1; }
};
struct A {
virtual int f() = 0;
};
// Imagine a trampoline class AT for A here
PYBIND11_MODULE(example, m) {
pybind11::class_<M>(m, "Mixin")
.def("f", &M::f);
pybind11::class_<A, AT>(m, "Abstract")
.def("f", &A::f);
}
class Derived(M, A):
...
d = D()
d.foo()
The last statement throws "Tried to call pure virtual function". For example in plain Python this works as expected:
class A():
def f(self):
pass
class M:
def f(self):
return "mixed in"
class D(M, A):
pass
d = D()
print(d.f())
Is this a regression? Put the last known working version here if it is.
Not a regression
Added an example