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

Nindi Singh nindi73 at yahoo.co.uk
Sat Oct 14 23:38:45 CEST 2006



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>());
    theClass_.def("GetType",&MyTestClass::GetType);
    
}


then the output in python is 


>>> a = TestClass(True)
>>> a.GetType()
'Int'
>>> a = TestClass(10)
>>> a.GetType()
'Int'
>>> a = TestClass(bool(True))
>>> a.GetType()
'Int'
>>>      


I cannot see what I am doing wrong, as I understand from http://mail.python.org/pipermail/c++-sig/2005-September/009503.html  that it should work.
I am using boost 1.33








        
___________________________________________________________ 
Try the all-new Yahoo! Mail. "The New Version is radically easier to use" – The Wall Street Journal 
http://uk.docs.yahoo.com/nowyoucan.html





	
	
		
___________________________________________________________ 
All new Yahoo! Mail "The new Interface is stunning in its simplicity and ease of use." - PC Magazine 
http://uk.docs.yahoo.com/nowyoucan.html



More information about the Cplusplus-sig mailing list