[C++-sig] pass float from python to c++ as reference
Sebastian Walter
walter at mathematik.hu-berlin.de
Tue Feb 19 11:48:44 CET 2008
Hello,
I need to pass a float from Python to C++ as a reference. What is the best
way to do that? I can't find it in the unit tests:
boost_1_34_1/libs/python/test/test_builtin_converters.cpp
/* by_reference.cpp */
#include <boost/python.hpp>
void by_reference(double &x){
x = 23.;
}
BOOST_PYTHON_MODULE(mymodule)
{
using namespace boost::python;
def("by_reference", by_reference);
}
/* by_reference.py */
import mymodule
x = 1.
print x
mymodule.by_reference(x)
print x
/* output */
>>Traceback (most recent call last):
>> File "./test.py", line 7, in <module>
>> mymodule.by_reference(x)
>>Boost.Python.ArgumentError: Python argument types in
>> mymodule.by_reference(float)
>>did not match C++ signature:
>> by_reference(double {lvalue})
thanks in advance,
Sebastian Walter
More information about the Cplusplus-sig
mailing list