[C++-sig] Problem with overloading between int and double

Jim Bosch talljimbo at gmail.com
Thu May 20 03:41:52 CEST 2010

On 05/19/2010 06:23 PM, Thomas Daniel wrote:
> The python wrappers created by boost don't seem to distinguish between
> create(int) and create(double), although they do notice create(const char*):
> Any ideas what I do wrong?

You aren't doing anything wrong.  The problem is that the boost.python 
overload matcher for double also matches integers (I think it probably 
should, generally), and that's getting tried first; only when the first 
overload fails does Boost.Python try another.

A workaround is to change the order to expose them (the last one exposed 
gets tried first):

         .def("create", (Test (*)(double))&Test::create)
         .def("create", (Test (*)(int))&Test::create)
         .def("create", (Test (*)(const char*))&Test::create)

I admit it's not a very satisfying solution.  Maybe someone else has a 
better idea, but I think fixing this in Boost.Python would require a lot 
of work.

Jim Bosch

More information about the Cplusplus-sig mailing list