Replies: 1 comment
-
Dereferencing the output of the factory function solved my issue. For completeness: nb::class_<Foo>(m, "Foo")
.def("__init__", [](Foo* t, std::string x, std::variant<std::string, Eigen::Matrix4d> y) { new (t) Foo(*createFoo(x, y)); }); Perhaps the section in the documentation can be updated to reflect this by adding an example of a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I want to create a binding to a struct that has the following two constructors:
Unfortunately the
Eigen::Isometry3d
in the second constructor is not (yet) supported. As an alternative, I want to create a custom constructor that instead takes anEigen::Matrix4d
as input, which I can then convert to the right type before passing it to the original constructor ofFoo
.My first attempt was to create a class that inherits from the
Foo
class and creates the new constructor. An object of this new type worked as expected. However, a lot of the member functions and other functions of the library use or return the base type. Therefore I also need to expose the base class to Python to use these functions creating two different types or extend all these methods and classes to use the new class.The documentation also tells its possible to combine a lambda function with a factory method to create a custom constructor. This sounded exactly like what I wanted, except I could not get this to work.
I created a factory function:
And tried to fill this in using the example given:
Which I think should then result in:
This results in the following error:
What am I doing wrong here? Is there an easier method to add a constructor to the struct or create some kind of auto conversion between the types?
Beta Was this translation helpful? Give feedback.
All reactions