[C++-sig] python bool not C++ bool

David Abrahams dave at boost-consulting.com
Fri Oct 20 03:48:11 CEST 2006


Nindi Singh <nindi73 at yahoo.co.uk> writes:

> I would very much like to pass bools from python to C++ and have them accepted as bools. However I cannot seem to do this.
> My code 
>
> class MyTestClass {
> public:
>     MyTestClass ():theType("Empty"){}
>     MyTestClass(bool theBool):theType("Bool"){}
>     MyTestClass(int theInt):theType("Int"){}
>     object GetType(){return object(theType);}
>     std::string theType;
> };
>
> void exportTestClass() {
>     class_<MyTestClass> theClass_("TestClass");
>     theClass_.def(init<bool>());
>     theClass_.def(init<int>());

Just exchange the two lines above and it will work.  However, you may
not be able to overload between int and Bool.  Boost.Python tries
overloads in reverse order of definition.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list