[英]pybind11 bad_alloc problem with std::vector<std::shared_ptr<A>>
I have structs like this: 我有这样的结构:
struct A{
void do_stuff(){...does stuff};
}
struct B{
std::vector<std::shared_ptr<A>> objs;
}
my pybind: 我的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 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. 类A本身起作用,但在遍历B时无效。如果此代码不够用,请在注释中写。 Thanks! 谢谢!
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. 它比我发布的还要复杂,因为我使用重载,并且我从调用子虚拟方法的父类中调用虚拟方法-pybind11无法处理此行为。 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 如果您在具有复杂类结构的PYBIND11_OVERLOAD周围遇到错误-请写评论或给我发邮件-相信我可以帮您
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.