The functionality and use of pybind11 is very similar to Boost.Python, the bonus being that pybind11 is a more lightweight dependency – although we will require C++11 support from the compiler. The interface definition in account.hpp is rather similar to that in the previous recipe:
#include <pybind11/pybind11.h>// ...namespace py = pybind11;PYBIND11_MODULE(account, m) { py::class_<Account>(m, "Account") .def(py::init()) .def("deposit", &Account::deposit) .def("withdraw", &Account::withdraw) .def("get_balance", &Account::get_balance);}
Again, we can clearly recognize how Python methods are mapped to C++ functions. The library that interprets PYBIND11_MODULE is defined in the imported target pybind11::module, which we have included ...