Skip to content
Discussion options

You must be logged in to vote

Hi Nick,

when you bind classes with a parent–child relationship (via multiple nb::class_<> calls), nanobind assumes that conversion between ChildClass and ParentClass can be done using an address-preserving cast: it treats a ChildClass* as a ParentClass* with the same pointer value.

In standard C++, that is not guaranteed once you have multiple or virtual inheritance. Converting ChildClass* to ParentClass* may require pointer adjustment, and the correct way to do that in all cases is to use the language-defined conversions (static_cast / dynamic_cast), which are free to change the pointer value to point at the appropriate base subobject.

To keep complexity down, nanobind intentionally doe…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@nmwsharp
Comment options

Answer selected by nmwsharp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants