[C++-sig] overloaded constructor, problem with int and bool

Wolfgang Langner wl at flexis.de
Wed Sep 29 13:45:16 CEST 2004


Hello,

I have a C++ class that can be initialized with (double, int and bool).
With the following constructor it's not possible to init with a bool value:

class_<Value>("Value")
       .def(init<>())
       .def(init<double>())
       .def(init<bool>())
       .def(init<int>());

Because int is the last entry and it wins.
Bool constructor is never called.
example:
v = Value(False)
-> v = Value(0) and int constructor is called

Is there a way to get this working ?

I tried to change the order and got other strange results.
With order

       .def(init<int>())
       .def(init<bool>())
       .def(init<double>());

all initializations with int are converted to use the double constructor.
v = Value(10) results in a call to the double constructor and Value
has the wrong type.

Search trough documentation and Mailing list returned no results.

Environment:
Boost Version 1.31.0, VisualStudio .Net 2003 (VC7.1), Windows XP SP1.
(STLPort 4.5.3)


bye by Wolfgang




More information about the Cplusplus-sig mailing list