Skip to content

Function arguments by reference #134

@ianhbell

Description

@ianhbell

I know dealing with references is never easy when wrapping low-level languages in high-level languages (I've fought with this in SWIG and Cython), but how would I get a dummy function like this working:

void plus_one_inplace(int &i) { i++; }

I tried:

PYBIND11_PLUGIN(ex) {
    py::module m("ex", "example");
    m.def("plus_one_inplace", &plus_one_inplace, "add one inplace");
    return m.ptr();
}

but when I do

i=1
ex.plus_one_inplace(i)

i is still equal to 1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions