Replies: 1 comment 1 reply
-
This is a basic C++ issue and not related to nanobind. A reference is a temporary thing, and your
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I’m just getting started with nanobind and need to wrap a C++ class that stores a reference to a
std::string
. Here is a small example:When invoking
Greeter("Hello").print()
on the Python side, this crashes or prints garbage, presumably because the temporarystd::string
is deleted after theGreeter
has been constructed. I added thenb::keep_alive<1, 2>()
in an attempt to prevent that, but it did not make a difference.I suspect I’m misunderstanding how
keep_alive
or perhaps type casters work and would appreciate a hint.Beta Was this translation helpful? Give feedback.
All reactions