Replies: 3 comments 10 replies
-
This is called the "diamond problem". Both, CppDerivedClass and PyBase derive from CppBase. So, you get two independent copies of CppBase inside your PyDerived. |
Beta Was this translation helpful? Give feedback.
-
not sure if that would fix your issue but : class PyDerived(CppDerivedClass, PyBase):
def __init__(self):
print("PyDerived __init__")
CppDerivedClass.__init__(self)
PyBase.__init__(self) is incorrect I believe. You should better have: class PyBase(CppBaseClass):
def __init__(self):
print("PyBase __init__")
super().__init__()
class PyDerived(CppDerivedClass, PyBase):
def __init__(self):
print("PyDerived __init__")
super().__init__() |
Beta Was this translation helpful? Give feedback.
-
Thank you very much for your answers. Regarding the use of class PyBase(CppBaseClass):
def __init__(self):
print("PyBase __init__")
super().__init__()
class PyDerived(CppDerivedClass, PyBase):
def __init__(self):
print("PyDerived __init__")
super().__init__()
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm new with pybind11 so I'm not sure if what I'm goint to ask makes sense...
Anyway, I have a base and a derived class in the C++ side (
CppBase
andCppDerived
) binded with pybind.I want to extend those classes in the python side (
PyBase
andPyDerived
) while maintaining the inheritance in both python and C++ sides. Something like this:So I tried using the following code:
And the output is:
Everything seems to work as expected, but the constructor is called twice.
Later on, when deleting the instance, the destructor is also called twice.
Is there something I'm missing?
Is there any workaround to still have the inheritance but not calling the constructor twice?
Beta Was this translation helpful? Give feedback.
All reactions