Replies: 3 comments 1 reply
-
Hi, of course it is possible. It is all in docs: https://pybind11.readthedocs.io/en/stable/advanced/classes.html#operator-overloading If you have your operator defined like this (where double operator+(A a) const { return _n + a._n; }; Then you are able to bind it with: cls.def(py::self + py:self);
cls.def(py::self + double()); // this cover your case of automatic cast |
Beta Was this translation helpful? Give feedback.
-
Hi @jiwaszki 1 - What's because the operator+ is not const, i'm using an external library where operators are not const... How can i deal with ? 2 - Moreover, given a construcor Thanks. |
Beta Was this translation helpful? Give feedback.
-
Hi @jiwaszki For sure, lambda helps a lot ! |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have a class A with a method operator+(A a) and also a constructor with a double parameter (defined as py::init )
I 'd like to write such expression a+2.5 with an automatic cast, is it possible ?
Best regards.
Beta Was this translation helpful? Give feedback.
All reactions