[C++-sig] overloaded functions and order of arguments

Holger Brandsmeier brandsmeier at gmx.de
Thu Apr 12 18:48:36 CEST 2012


Dear list,

I exported the C++ function `sin` both for real and complex numbers
(`float` and `complex` in python / `double` and `std::complex` in C++)
and I noticed that calling `sin(2.3)` gives `(0.7457052121767203-0j)`
so a complex number. Why is that? In which order does boost python
handle overloading of functions anyways?


More precisely I exported this function to python

>>> sin?
Type:           function
Base Class:     <type 'builtin_function_or_method'>
String Form:    <Boost.Python.function object at 0x26358e0>
Namespace:      Interactive
Docstring:
    sin( (float)arg1) -> float :

        C++ signature :
            double sin(double)

    sin( (complex)arg1) -> complex :

        C++ signature :
            std::complex<double> sin(std::complex<double>)

Notice in particular that the `float` version is above the `complex`
version, so if boost::python things this is ambiguous (I don't
condider this abiguous), but even if so I was kind of expecting him to
use the first exported function, not the second.

Any ideas?
-Holger


More information about the Cplusplus-sig mailing list