[C++-sig] Passing a c++ new'ed object back to python

Stefan Seefeld seefeld at sympatico.ca
Tue Jun 23 21:09:35 CEST 2009


On 06/23/2009 02:59 PM, Simon Pickles wrote:
>
> When I use code which parallels this structure, I see the Model 
> destructor is called when the c++ object goes out of scope (fine) 
> despite the object being passed to python as the argument of a 
> function (not fine!)

That is because by default arguments are passed by-value. If you want 
something else, you need to specify a return-value policy, such as 
manage_new_object.


>
> Is there a return policy I need to provide? I am confused by the way 
> the destructing class is new'ed in c++ code, not in python by using 
> exposed c++.

boost.python wants to pass a Model, and thus makes a copy. from the 
object you pass back, then destructs it.

Regards,
         Stefan


-- 

       ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list