[C++-sig] Convert C++ Class to exposed class and back

Marcus Jannes jannes80 at hotmail.de
Tue Feb 12 13:24:23 CET 2008

Hi again,

i know the following code should work:

double pycall(double d){
        PyObject *py_obj;
        double c_result;
        py_obj = Py_BuildValue("d",d);
        c_result = PyFloat_AS_DOUBLE(py_obj);
        return c_result;

But how can i use a boost.python exposed class with it (i.e.: ExpClass):

c_class pycall(c_class c){
        PyObject *py_obj;
        c_class c_result;
        py_obj = PyBuildValue("O",c); //does not work! Provide converter function with "O&" argument ?
        c_result = SomeConverterToC(py_obj); //???
        return c_result;

         typedef bp::class_< ExpClass> ExpClass_exposer_t;
         ExpClass_exposer_t ExpClass_exposer = ExpClass_exposer_t( "PyExpClass" );
         bp::scope ExpClass_scope( ExpClass_exposer );

         ExpClass_exposer.def( bp::init<>() ); //default constructor
         ExpClass_exposer.def( bp::init< ExpClass const &>(( bp::arg("r") )) ); //copy-constructor

Thanks again for any help.

Kostenlose Messenger Emoticons! Hier downloaden!

More information about the Cplusplus-sig mailing list