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

Adam Hupp hupp at cs.wisc.edu
Fri May 2 18:41:02 CEST 2003


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




More information about the Cplusplus-sig mailing list