Skip to content
Discussion options

You must be logged in to vote

The order is irrelevant as long as all classes are registered before any of the bound methods is actually invoked from Python — which, for the pattern in your snippet (everything inside one PYBIND11_EMBEDDED_MODULE / PYBIND11_MODULE), is automatically the case.

The mechanism:

  • py::class_<T>(m, "T") registers T in pybind11's internal type registry (a hash map keyed by std::type_index).
  • library.def("FindBook", &Library::FindBook, ...) does not resolve Book at registration time. It only stores enough type info to convert the return value later, at call time.
  • When Python actually calls library.FindBook(123) and pybind11 needs to hand back a Book*, it looks up typeid(Book) in the registry. If B…

Replies: 1 comment 1 reply

Comment options

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

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