I am trying to build a simple nanobind module which shares ownership of, for example, an integer between C++ and Python.
#include <nanobind/nanobind.h>
#include <nanobind/stl/shared_ptr.h>
class TestClass {
public:
std::shared_ptr<int> i;
TestClass(std::shared_ptr<int> i) : i(i) {}
};
NB_MODULE(test_module, m) {
nanobind::class_<TestClass>(m, "TestClass")
.def(nanobind::init<std::shared_ptr<int>>());
}
When I compile, nanobind seems to have some issue with the argument of the constructor:
.../site-packages/nanobind/include/nanobind/stl/shared_ptr.h:67:19: error: static assertion failed: Conversion of ``shared_ptr<T>`` requires that ``T`` is handled by nanobind's regular class binding mechanism. However, a type caster was registered to intercept this particular type, which is not allowed.
static_assert(is_base_caster_v<Caster>,
^~~~~~~~~~~~~~~~~~~~~~~~
I haven't seen an issue like this mentioned before; what am I doing wrong here?