[C++-sig] Passing by reference from Pythont to C++

Patrick Hartling patrick at vrac.iastate.edu
Fri May 2 19:02:07 CEST 2003

Ah, I see.  Well, the solution you propose doesn't quite work for the 
real situation I'm facing (my example code was a bit too trivial), but it 
gave me a good idea for working around the problem.  Thanks very much.


Adam Hupp wrote:
> On Fri, May 02, 2003 at 11:30:56AM -0500, Patrick Hartling wrote:
>>I am pulling my hair out trying to figure out why the following code 
>>cannot be called from Python:
>>Is this an error in how I am using reftest.f() from Python, or is 
>>something missing from my BPL code?  I've written bindings for a lot of 
>>other code that used pass-by-reference semantics, but it was always with 
>>classes rather than floats (or ints or other built-in types).
> Ints and floats are immutable in python.  You'll need to create a
> wrapper function that returns the modified float:
> float f_wrap(float x) 
> {
> 	f(x);
> 	return x;
> }
> void f(float& x)
> {
>    x = 5.0f;
> }
> -Adam
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig

Patrick L. Hartling                     | Research Assistant, VRAC
patrick at vrac.iastate.edu                | 2624 Howe Hall: 1.515.294.4916
http://www.137.org/patrick/             | http://www.vrac.iastate.edu/

More information about the Cplusplus-sig mailing list