[C++-sig] Passing pointer to c++ functions.

David Abrahams dave at boostpro.com
Sun Feb 8 19:16:41 CET 2009


on Mon Feb 02 2009, yamini sardana <sardana.yamini-AT-gmail.com> wrote:

> Hi,
>
> How do we pass a pointer to a c++ function from python.
>
> I have to call the below mentioned function from python
>
> long afSigGenDll_Manual_LevelMax_Get(afSigGenInstance_t sigGenId, double*
> pLevelMax);
>
> When i am calling the function with the second argument as
> pLevelMax = pointer(c_double())
>
> its giving me an error:
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in <module>
> TypeError: in method 'afSigGenDll_Manual_LevelMax_Get', argument 2 of type
> 'double *'
>
> Please le me know what is the correct way to pass pointers as arguments to
> c++ functions.

You can't pass a non-const pointer because the python 'Float' type is
immutable; changing the double held by the python object (when indeed
there is one) would be disastrous.  If you want to modify this number
youi should wrap your C++ function in something that returns a Python
tuple containing a long and a double.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com


More information about the Cplusplus-sig mailing list