[Python] How do I return multiple values from Python to C++ via Pybind? [duplicate]

Discussão em 'Python' iniciado por Stack, Agosto 11, 2025.

  1. Stack

    Stack Membro Participativo

    I have a C++ program that is taking in a function pointer from Python to some Python code and since Pybind doesn't really allow passing by reference for a modified argument, I want to use Python's multiple return values to return the modified argument and something else. Basically, if I have a Python function that looks like

    def foo(var1):
    return True, (var+1)


    Is there a way to handle this on the C++ side other than bundle them into a class and pass it back that way? std::tuple, maybe?

    Continue reading...

Compartilhe esta Página