Swig: No Constructor defined

Posted by wheaties on Stack Overflow See other posts from Stack Overflow or by wheaties
Published on 2010-06-03T14:21:56Z Indexed on 2010/06/03 14:24 UTC
Read the original article Hit count: 377

Filed under:
|
|

I added %allowexcept to my *.i file when building a Python <--> C++ bridge using Swig. Then I removed that preprocessing directive. Now I can't get the Python produced code to recognize the constructor of a C++ class. Here's the class file:

#include <exception>

class Swig_Foo{
public:
    Swig_Foo(){}
    virtual ~Swig_Foo(){}

    virtual getInt() =0;
    virtual throwException() { throw std::exception(); }
};

And here's the code Swig produces from it:

class Swig_Foo:
    __swig_setmethods__ = {}
    __setattr__ = lambda self, name, value: _swig_setattr(self, Swig_Foo, name, value)
    __swig_getmethods__ = {}
    __getattr__ = lambda self, name: _swig_getattr(self, Swig_Foo, name)
    def __init__(self): raise AttributeError, "No constructor defined"
    __repr__ = _swig_repr
    __swig_destroy__ = _foo.delete_Swig_Foo
    __del__ = lambda self : None;
    def getInt(*args): return apply(_foo.Swig_Foo_getInt, args)
    def throwOut(*args): return apply(_foo.Swig_Foo_throwOut, args)
Swig_Foo_swigregister = _foo.Swig_Foo_swigregister
Swig_Foo_swigregister(Swig_Foo)

The problem is the def __init__self): raise AttributeError, "No constructor defined" portion. It never did this before I added the %allowexception and now that I've removed it, I can't get it to create a real constructor. All the other classes have actual constructors. Quite baffled.

Anyone know how I can get it to stop doing this?

© Stack Overflow or respective owner

Related posts about c++

Related posts about python