I have a C++ class Box that I want to wrap up using python C++ api.
The class is defined as:
class Box {
public:
int id;
Box(double l, double b, double h);
double getVolume(void);
void setLength( double len );
private:
double length; // Length of a box
double breadth; // Breadth of a box
double height; // Height of a box
};
In the C-API I have the following declaration of PyBox:
typedef struct
{
PyObject_HEAD
Box *bx;
} PyBox;
and the following members table:
static PyMemberDef pyBox_members[] = {
{"id", T_INT, offsetof(PyBox, bx->id), 0, "Box id"},
{NULL} /* Sentinel */
};
However, when I try to compile the module I get the following error message:
error: cannot apply ‘offsetof’ to a non constant address
{"id", T_INT, offsetof(PyBox, bx->id), 0, "Box id"},
^~~~~~~~
How do I specify the correct offsetof so that the member id corresponds to the public attribute bx->id?
Thanks!