typecasting in Python across C++ hierarchy after SWIG
mmukin at totallygames.com
mmukin at totallygames.com
Mon Oct 9 20:10:30 EDT 2000
I'm a new Python user and have the following problem:
In C++ I have hierarchy like
class A ...
class B : public A
class C : public B
I have a C++ function that actually creates one of A, B, C but return
A*
A* func( some_args_like_AorBorC_to_create );
In C++, I use casting
B* b = (B*)func( some_create_B_args );
b->Method();
I need to allow access to such creation and access to resulting A, B,
C member functions in Python.
Python 1.5.2 is used and SWIG (Version 1.1 (Patch 5)).
============
I tried
b = ModuleName.BPtr( func(blablabla) )
b.Method()
but in b.Method() line I got an error - "expected string, got
instance". Error originated in C wrapper func for the method (Method
is actually defined as public in A)
static PyObject *_wrap_A_Method(PyObject *self, PyObject *args) {
...
PyArg_ParseTuple(args,"s:A_Method",&_argc0) <-- returned NULL!
...
So I think I did something wrong with typecasting. It works if I use
it directly on A without conversion to B like
a = func(blablabla)
a.Method()
Please help,
Thank you!
Mike.
More information about the Python-list
mailing list