[英]pybind11 bad_alloc problem with std::vector<std::shared_ptr<A>>
我有這樣的結構:
struct A{
void do_stuff(){...does stuff};
}
struct B{
std::vector<std::shared_ptr<A>> objs;
}
我的pybind:
py::class_<A>(m, "A")
.def("do_stuff", &A::do_stuff)
py::class_<B>(m, "B")
.def_readwrite("objs", &B::objs);
我嘗試達到的行為:
import mybind
b_instance = mybind.B()
for a_instance in b_instance:
a_instance.do_stuff()
不幸的是,我得到了
MemoryError:std :: bad_alloc
請幫幫我。 上面的代碼實際上不是我使用的代碼。 類A本身起作用,但在遍歷B時無效。如果此代碼不夠用,請在注釋中寫。 謝謝!
我發現出了什么問題。 它比我發布的還要復雜,因為我使用重載,並且我從調用子虛擬方法的父類中調用虛擬方法-pybind11無法處理此行為。 我修好了。 如果您在具有復雜類結構的PYBIND11_OVERLOAD周圍遇到錯誤-請寫評論或給我發郵件-相信我可以幫您
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.