Skip to content

Small .def_property issue and possible clarification needed #5210

Answered by jiwaszki
luis605 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @luis605 , I am not sure about all details of your library. However it is possible, you need to return pointer to the vector structure. If you don't do this, there is no proper ownership over the vector which results in "no updates". It might not be a perfect solution, you can probably do it in a slightly different way without exposing getPos and getting policies right to fit your needs/project. You can read more about returning values here: https://pybind11.readthedocs.io/en/stable/advanced/functions.html#return-value-policies

Cheers, I hope that helps!

Here is small reproducer:

class Vector3 {
public:
    Vector3(int _x, int _y, int _z): x(_x), y(_y), z(_z) {}

    int x;
    int y;
…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by luis605
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants