SWIG - C++ - Inheritance
David Abrahams
david.abrahams at rcn.com
Mon Sep 30 16:22:55 EDT 2002
"news1.sympatico.ca" <mtremblay at golemlabs.com> wrote in message
news:d31m9.3742$Qh1.491539 at news20.bellglobal.com...
> Hello,
>
> The problem comes when I come to create a new class in python that
inherits
> from CThread. Here is the python code sample
> =============== test.py =================
> import my_module
>
> class MyThread(my_module.CThread):
> def __init__(self):
> pass
> def process(self):
> print "hey"
>
> a = MyThread()
> a.run()
> ============================================
> my_module is exposed to Python using SWIG. When I try to execute this, I
> get the following error :
>
> #############################################
> Traceback (most recent call last):
> File "U:\Alexandra\test\pythontool\martin.py", line 14, in ?
> a.run()
> File "U:\Alexandra\test\pythontool\hector.py", line 649, in run
> def run(*args): return apply(_hector.CThread_run,args)
> TypeError: Type error. Expected _p_CThread
> #############################################
>
> It appears that the swig module does not recognize the a variable as a
> CThread. I guess there is something I am doing wrong. It does not even
> call the process function so the problem does not appear to be with the
pure
> virtual function. Anybody can help ? It would be really appreciated.
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.
--
-----------------------------------------------------------
David Abrahams * Boost Consulting
dave at boost-consulting.com * http://www.boost-consulting.com
More information about the Python-list
mailing list