vendredi 4 mars 2022

pybind11 bind input output parameter

my C++ code

void test(std::string & data) {
    data += " github";
}

PYBIND11_MODULE(example11, m) {
    m.def("test", [](std::reference_wrapper<std::string> w) {
test(w.get());
    });
}

my python code

import example11

def my_test():
    data = "hello"
    example11.test(data)
    print("python: {}".format(data))

if __name__ == '__main__':
    my_test()

what i expect is i got hello github, however hello is gotten, is there something wrong in my code, dear guys?

Aucun commentaire:

Enregistrer un commentaire