I have a class that looks like
class Foo{
Foo();
Foo(int i);
Foo(bool b);
Foo(double d);
};
and I expose my class to python as usual
class_<Foo>("Foo")
.def(init<int>())
.def(init<bool>())
.def(init<double>());
when I try to use to in python, the python code always cast the c’tor parameter into double (which is always the last one in the class def export). Is there a way to explicit tell boost.python how to explicitly handle by the type?
Well, you can change the order of constructor’s definitions, the last one will have higher priority. Here is my results:
As you see, it’s not a perfect solution. So, if you really need to make overloaded constructors work I suggest to roll your own factory function.
And using makeFoo:
By the way, docs at python.org can be somewhat helpful.