[C++-sig] call Python function from C++ without copying the arguments (original) (raw)

David Abrahams dave at boostpro.com
Sat Jan 17 13:38:19 CET 2009


on Sat Jan 17 2009, "Sebastian Walter" <walter-AT-mathematik.hu-berlin.de> wrote:

Hello,

I want to call a Python function from C++ with an object of a C++ class as argument. The Python-function should change the argument, so changes are visible on the C++ side. Boost::Python automatically makes a copy of all the arguments that are passed to a callable Python object. Is there a way NOT to copy all arguments??

void mytestfunction(object funobj){ A a; cout<<"a.x="<<a.x<<endl; funobj(a);

      fun_obj(boost::ref(a))
              ^^^^^^^^^^^ ^

cout<<"a.x="<<a.x<<endl; }

HTH,

-- Dave Abrahams BoostPro Computing http://www.boostpro.com



More information about the Cplusplus-sig mailing list