If I am using boost.python or pyplusplus, how do I wrap an int pointer, or any pointer that is a member variable of a class?
For example, how would I wrap x
from the following class:
class Foo{
int * x;
}
If I am using boost.python or pyplusplus, how do I wrap an int pointer, or any pointer that is a member variable of a class?
For example, how would I wrap x
from the following class:
class Foo{
int * x;
}
First you need to expose the class and properties to Python.
#include <boost/python.hpp>
BOOST_PYTHON_MODULE(mylib)
{
using namespace boost::python;
class_<Foo>("Foo")
.def_readwrite("x", &Foo::x);
}
Invoking the class in Python is similarly simple.
>>> import mylib
>>> fooObj = mylib.Foo()
>>> fooObj.x = 3
>>> print 'fooObj.x is ', fooObj.x
fooObj.x is 3