[C++-sig] Calling member function of object created in C++ via embedded Python

John Reid j.reid at mail.cryst.bbk.ac.uk
Wed Apr 18 18:31:50 CEST 2007


If I have you right you might try this:

typedef boost::shared_ptr< World > world_ptr;
world_ptr worldObject( new World ), worldObject2;

...

worldObject2 = extract<world_ptr>(resultObject);


If you pass pointers to objects around instead of objects by value you 
will probably have more luck. The following line as it stands forces use 
of the copy constructor (if worldObject is of type World)
dictionary["pyWorldObject"] = worldObject

For boost.python to work with world_ptrs you will need to tell it about 
them, so add this to the BOOST_PYTHON_MODULE:

register_ptr_to_python( world_ptr );


There may be typos in the above but I think this is along the right sort 
of lines....

John.




More information about the Cplusplus-sig mailing list