python访问struct中的struct

boost::python access struct within struct

本文关键字:struct 中的 访问 python      更新时间:2023-10-16

有两个结构体:

struct A {
  float x,y;
};
struct B {
  A my_A;
};

我试图使用boost::python设置绑定来访问my_A。到目前为止,我有:

using boost::python;
scope in_B = class_<B>("B")
  .def_readwrite("my_A", B::my_A);
class_<A>("A")
  .def_readwrite("x", &A::x)
  .def_readwrite("y", &A::y);

,但这不允许我检索B.my_A.x。欢迎提出任何建议。

好吧,@imreal的评论是正确的;我的错误是访问了数据。我用B.A.x代替B.my_A.x