0

I have structs like this:

struct A{
  void do_stuff(){...does stuff};
}
struct B{
  std::vector<std::shared_ptr<A>> objs;
}

my pybind:

py::class_<A>(m, "A")
  .def("do_stuff", &A::do_stuff)
py::class_<B>(m, "B")
  .def_readwrite("objs", &B::objs);

Behaviour I'm trying to reach:

import mybind

b_instance = mybind.B()

for a_instance in b_instance:
  a_instance.do_stuff()

Unfortunately, I get

MemoryError: std::bad_alloc

Please, help me out. Code above is not actually the code I work with. Class A works by itself, but doesn't when iterating through B. If this code is not enough please write in the comments. Thanks!

1 Answers1

0

I found out what has been wrong. It's more complicated than I posted, because I use overload, and I invoke virtual method from parent class that invokes child virtual method - pybind11 couldn't handle this behaviour. I have it fixed. If you have mistakes around PYBIND11_OVERLOAD with complex class structure - write a comment or mail me - I believe I can help