Skip to content

Rvalue reference parameters work in constructors, but not in other functions #1694

Closed
@Boris-Rasin

Description

@Boris-Rasin
struct example {
    example(std::string&&) {}
    void name(std::string&&) {}
};

pybind11::class_<example>(m, "example")
    .def(pybind11::init<std::string&&>()) // this works
    .def<void(example::*)(std::string&&)>("name", &example::name) // this doesn't
;

Error message:

/usr/local/include/pybind11/pybind11.h:72:74: error: rvalue reference to type 'basic_string<...>' cannot bind to lvalue of type 'basic_string<...>'
initialize([f](Class *c, Arg... args) -> Return { return (c->*f)(args...); },

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