Search code examples
c++boost-python

boost::python access struct within struct


I have two structs:

struct A {
  float x,y;
};

struct B {
  A my_A;
};

I'm trying to set up bindings using boost::python to access my_A. So far, I have:

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);

but this does not allow me to retrieve B.my_A.x. Any suggestions would be welcome.


Solution

  • Okay, so @imreal's comment was spot on; my mistake was in accessing the data. I used B.A.x instead of B.my_A.x. That did it.