SWIG - C++ - Inheritance

David Abrahams david.abrahams at rcn.com
Tue Oct 1 14:13:07 CEST 2002

"news1.sympatico.ca" <mtremblay at golemlabs.com> wrote in message
news:gDgm9.3159$zz2.655136 at news20.bellglobal.com...
> "David Abrahams" <david.abrahams at rcn.com> wrote in message

> > I don't know much about SWIG, but if it's anything like Boost.Python the
> > problem is that you've shielded the base class __init__ function.
> Something
> > has to create the C++ CThread object, and it would make sense if
> > CThread.__init__ were responsible for that job. Just remove the __init__
> > function from MyThread, or have it call CThread.__init__(self) and you
> > should be OK.
> >
> > --
> Thanks for the answer, the problem that I see then is that my CThread
> is an abstract class since it has a pure virtual function, and when Swig
> notices a pure virtual function, it defines the constructor as the
> :
>     def __init__(self): raise RuntimeError, "No constructor defined"

Ooh, that's bad! How can you ever construct the C++ instance data you need?
I guess you'd better ask the SWIG people about this; I'm out of my depth

If you don't have too much invested in SWIG you could switch to
Boost.Python, which handles abstract classes fairly smoothly. A pure virtual
function just means that you'll get an AttributeError if you try to use
/that function/ without implementing it.

           David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com

More information about the Python-list mailing list