Hi,
I'm a newbie having some problems instantiating a class written in C++
in Python using Boost.Python.
I can get a very simple example working when I expose a function outside
of a class, that returns a string, but the below fails as shown, despite
building. The enum in the same library however works fine.
I've googled the error returned from Python and I get zero hits - has
anyone get any idea what I'm doing wrong?
I'm using Python 2.5, GCC 4.0.1 and Boost 1.33 on Mac OS X 10.4.9. I
don't think it matters but I'm building the solution as a dynamic C++
bsd library in XCode and the changing the Mac OS X .dylib extention to
.so as is required by Python. This all works for simpler examples and
the enum in this example.
Error: TypeError: __init__() should return None, not 'NoneType'
Thanks,
Phil.
From header file example.h:
enum payOffType { CALL, PUT };
class Option
{
public:
//defaults to call
Option( double strike, double expiry );
double getPutCallMultiplier();
private:
double strike;
double expiry;
payOffType type;
};
From cpp file example.cpp:
Option::Option( double strike, double expiry ) : strike( strike ),
expiry( expiry ), type( CALL )
{
cout << "Option Contructor called";
}
double Option::getPutCallMultiplier()
{
return ( type == CALL ) ? 1 : -1;
}
BOOST_PYTHON_MODULE(libphil_boost)
{
class_<Option>("Option", init
import libphil_boost p = libphil_boost.Option( 23, 23 ) Option Contructor calledTraceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: __init__() should return None, not 'NoneType'