[C++-sig] BoostPython: C++ function with "non-const double reference" argument issue. Python looks for float causing argument mismatch.

Liam Herron herron at ELLINGTON.com
Tue Jan 14 00:01:35 CET 2014


Here is my example:

-------------------------------------------------------------------------------------------
CPP Code:
-------------------------------------------------------------------------------------------
#include <boost/python.hpp>
using namespace boost::python;


void updateDoubleReference(double& x)
{
  x = x + 5.4321;
}


BOOST_PYTHON_MODULE(_testDR)
{
    // Add regular functions to the module.
    def("updateDoubleReference", &updateDoubleReference );
}
-------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------
PY Code:
-------------------------------------------------------------------------------------------
#!/usr/bin/python
#
#

from _testDR import *

x = 3.0
updateDoubleReference(x)
--------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------
ERROR OUTPUT
-------------------------------------------------------------------------------------------
python2.5 testDR.py
Traceback (most recent call last):
  File "testDR.py", line 8, in <module>
    updateDoubleReference(x)
Boost.Python.ArgumentError: Python argument types in
    _testDR.updateDoubleReference(float)
did not match C++ signature:
    updateDoubleReference(double {lvalue})
-------------------------------------------------------------------------------------------


How do people typically handle this issue?   Wrap the function with 'float' versions of the arguments?  I tried to create a 'NativeDouble' struct that had a double member attribute but when exposed to python, it simply interprets this as a float and it still has a mismatch.

Any help would be greatly appreciated.

Thanks,
Liam








=============================================================================================
Email transmissions can not be guaranteed to be secure or error-free, as information 
could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or contain 
viruses.  The sender therefore does not accept liability for any errors or omissions in 
the contents of this message which arise as a result of email transmission.  In addition,
the information contained in this email message is intended only for use of the 
individual or entity named above.  If the reader of this message is not the intended
recipient, or the employee or agent responsible to deliver it to the intended recipient,
you are hereby notified that any dissemination, distribution,or copying of this communication,
disclosure of the parties to it, or any action taken or omitted to be taken in reliance on it,
is strictly prohibited, and may be unlawful.  If you are not the intended recipient please
delete this email message. 
==============================================================================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20140113/12d08aa6/attachment.html>


More information about the Cplusplus-sig mailing list