How to make a Python callback funtion match (i.e. become compatible with) a pybind11 C++ class constructor signature? #5996
Unanswered
TrondMelen
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I try to make a Python interface to an existing API represented by a C++ class where internal events trigger the execution of registered callbacks. I would be grateful if someone can help. Thanks in advance!
The simplified case below demonstrates my problem. The C++ 'My_class' constructor expects one argument of type '(void (data_s const&))', but to Python this is incompatible with '<function my_data_handler at 0x7fef4d1fc180>'. The class instantiation fails with the Python error message "
TypeError: __init__(): incompatible constructor arguments." I guess I must either relax the C++ type or tighten the Python type. Right?The C++ file 'My_class.hpp' defining (header only) 'My_class':
The pybind11 C++ file 'binder.cpp':
The Python program 'main.py' that fails:
The failing interactive Python session:
Pybind11 is version 2.13.6
Beta Was this translation helpful? Give feedback.
All reactions